Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions CefSharp.Core.Runtime/Internals/CefSharpApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,42 @@ namespace CefSharp

if (kvp->Key == "disable-features" || kvp->Key == "enable-features")
{
//Temp workaround so we can set the disable-features/enable-features command line argument
// See https://github.com/cefsharp/CefSharp/issues/2408
commandLine->AppendSwitchWithValue(name, value);
if (CefSharpSettings::MergeFeaturesCommandLineArgs)
{
CefString existingValue = commandLine->GetSwitchValue(name);
if (existingValue.empty())
{
commandLine->AppendSwitchWithValue(name, value);
}
else
{
bool missing = false;
String^ currentValue = StringUtils::ToClr(existingValue);
List<String^>^ existingFeatures = gcnew List<String^>(currentValue->Split(','));
for each(String ^ feature in kvp->Value->Split(','))
{
if (!existingFeatures->Contains(feature))
{
missing = true;
break;
}
}
if (missing)
{
commandLine->RemoveSwitch(name);
commandLine->AppendSwitchWithValue(name, StringUtils::ToNative(currentValue + "," + kvp->Value));
}
}
}
Comment on lines +212 to +238
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Substring matching causes incorrect duplicate detection for feature lists.

The Contains() check at Line 222 uses substring matching instead of parsing the comma-separated feature list, leading to correctness issues:

False positives (features incorrectly detected as present):

  • Existing: "AutofillActorMode", New: "Autofill" → Contains returns true, "Autofill" never added
  • Existing: "EnableHangWatcher", New: "Hang" → Contains returns true, "Hang" never added

Missing features when adding multiple features:

  • Existing: "Feature1", New: "Feature1,Feature2" → Contains returns true, "Feature2" never added

Correct approach:
Split both the existing value and the new value by commas, then check each individual feature for presence before merging.

🐛 Proposed fix using proper comma-separated list handling
                            if (CefSharpSettings::MergeFeaturesCommandLineArgs)
                            {
                                CefString existingValue = commandLine->GetSwitchValue(name);
                                if (existingValue.empty())
                                {
                                    commandLine->AppendSwitchWithValue(name, value);
                                }
                                else
                                {
-                                   String^ currentValue = StringUtils::ToClr(existingValue);
-                                   if (!currentValue->Contains(kvp->Value))
-                                   {
-                                       commandLine->RemoveSwitch(name);
-                                       commandLine->AppendSwitchWithValue(name, StringUtils::ToNative(currentValue + "," + kvp->Value));
-                                   }
+                                   String^ currentValue = StringUtils::ToClr(existingValue);
+                                   auto existingFeatures = gcnew HashSet<String^>(currentValue->Split(','));
+                                   auto newFeatures = kvp->Value->Split(',');
+                                   bool hasNewFeature = false;
+                                   for each (String^ feature in newFeatures)
+                                   {
+                                       if (!existingFeatures->Contains(feature))
+                                       {
+                                           existingFeatures->Add(feature);
+                                           hasNewFeature = true;
+                                       }
+                                   }
+                                   if (hasNewFeature)
+                                   {
+                                       commandLine->RemoveSwitch(name);
+                                       commandLine->AppendSwitchWithValue(name, StringUtils::ToNative(String::Join(",", existingFeatures)));
+                                   }
                                }
                            }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (CefSharpSettings::MergeFeaturesCommandLineArgs)
{
CefString existingValue = commandLine->GetSwitchValue(name);
if (existingValue.empty())
{
commandLine->AppendSwitchWithValue(name, value);
}
else
{
String^ currentValue = StringUtils::ToClr(existingValue);
if (!currentValue->Contains(kvp->Value))
{
commandLine->RemoveSwitch(name);
commandLine->AppendSwitchWithValue(name, StringUtils::ToNative(currentValue + "," + kvp->Value));
}
}
}
if (CefSharpSettings::MergeFeaturesCommandLineArgs)
{
CefString existingValue = commandLine->GetSwitchValue(name);
if (existingValue.empty())
{
commandLine->AppendSwitchWithValue(name, value);
}
else
{
String^ currentValue = StringUtils::ToClr(existingValue);
auto existingFeatures = gcnew HashSet<String^>(currentValue->Split(','));
auto newFeatures = kvp->Value->Split(',');
bool hasNewFeature = false;
for each (String^ feature in newFeatures)
{
if (!existingFeatures->Contains(feature))
{
existingFeatures->Add(feature);
hasNewFeature = true;
}
}
if (hasNewFeature)
{
commandLine->RemoveSwitch(name);
commandLine->AppendSwitchWithValue(name, StringUtils::ToNative(String::Join(",", existingFeatures)));
}
}
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@CefSharp.Core.Runtime/Internals/CefSharpApp.h` around lines 212 - 228, The
substring check using currentValue->Contains causes incorrect duplicate
detection; in the block gated by CefSharpSettings::MergeFeaturesCommandLineArgs
(around commandLine->GetSwitchValue/name handling), replace the Contains-based
logic with proper comma-separated token parsing: split the existingValue (via
StringUtils::ToClr(existingValue)) and the incoming kvp->Value by commas, trim
whitespace, build a case-sensitive set/list of existing tokens, iterate the
incoming tokens and add only those not already present, then reconstruct the
merged comma-separated string and call commandLine->RemoveSwitch(name);
commandLine->AppendSwitchWithValue(name, StringUtils::ToNative(mergedValue));
this ensures exact-feature matching and correctly handles multi-feature inputs
like "Feature1,Feature2".

else
{
//Temp workaround so we can set the disable-features/enable-features command line argument
// See https://github.com/cefsharp/CefSharp/issues/2408
commandLine->RemoveSwitch(name);
commandLine->AppendSwitchWithValue(name, value);
}
}

// Right now the command line args handed to the application (global command line) have higher
// precedence than command line args provided by the app
else if (!commandLine->HasSwitch(name))
Expand Down
7 changes: 7 additions & 0 deletions CefSharp/CefSharpSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ static CefSharpSettings()
WcfTimeout = TimeSpan.FromSeconds(2);
#endif
SubprocessExitIfParentProcessClosed = true;
MergeFeaturesCommandLineArgs = true;
}

#if !NETCOREAPP
Expand Down Expand Up @@ -82,6 +83,12 @@ static CefSharpSettings()
/// </summary>
public static bool FocusedNodeChangedEnabled { get; set; }

/// <summary>
/// Any enable-features/disable-features command line arguments will be automatically merged with existing values if supplied.
/// This currently defaults to true.
/// </summary>
public static bool MergeFeaturesCommandLineArgs { get; set; }

/// <summary>
/// CefSharp.WinForms and CefSharp.Wpf.HwndHost ONLY!
/// The default is to create <see cref="CefRuntimeStyle.Alloy"/>
Expand Down