Skip to content

ExecuteScriptAsync with parameters does not handle booleans #1728

@chylex

Description

@chylex

The version and architecture info don't matter, the bug is in the core and still present in master branch.

  • What version of the product are you using?
    49.0.0-pre2 from NuGet
  • What architecture x86 or x64?
    x86
  • On what operating system?
    Win 7
  • Are you using WinForms, WPF or OffScreen?
    WinForms
  • What steps will reproduce the problem?
    Using WebBrowserExtensions.ExecuteScriptAsync(this IWebBrowser browser, string methodName, params object[] args) to pass a boolean variable in the args converts it to "True" or "False" which are both truthy strings, therefore passing false will always result in true on JS side.
  • Please provide any additional information below.
    This would probably need a little bit of special casing, unfortunately adding the bool type to WebBrowserExtensions.numberTypes is not enough because Boolean.ToString capitalizes the first letter and JavaScript doesn't accept True/False despite being case-insensitive. So either special casing booleans or something like:
if (!numberTypes.Contains(obj.GetType()))
{
    stringBuilder.Append("'").Append(args[i].ToString()).Append("'");
}
else
{
    stringBuilder.Append(args[i].ToString().ToLowerInvariant());
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions