Skip to content

Commit

Permalink
Fix wxWebView::RunScript() with string containing backslashes
Browse files Browse the repository at this point in the history
Escape backslashes in wxJSScriptWrapper to allow strings with
backslashes in them to work again -- this was broken while implementing
support for returning values from JavaScript to C++.

See wxWidgets#741
  • Loading branch information
MaartenBent authored and vadz committed Feb 22, 2018
1 parent dd2d62c commit 3d427a1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/wx/private/jsscriptwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class wxJSScriptWrapper

// Adds one escape level if there is a single quote, double quotes or
// escape characters
wxRegEx escapeDoubleQuotes("(\\\\*)(['\"\n\r\v\t\b\f])");
wxRegEx escapeDoubleQuotes("(\\\\*)([\\'\"\n\r\v\t\b\f])");
escapeDoubleQuotes.Replace(&m_escapedCode,"\\1\\1\\\\\\2");
}

Expand Down
3 changes: 3 additions & 0 deletions tests/controls/webtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ void WebTestCase::RunScript()
CPPUNIT_ASSERT(m_browser->RunScript("function f(a){return a;}f('Hello World!');", &result));
CPPUNIT_ASSERT_EQUAL(_("Hello World!"), result);

CPPUNIT_ASSERT(m_browser->RunScript("function f(a){return a;}f('a\\\'aa\\n\\rb\vb\\tb\\\\ccc\\\"ddd\\b\\fx');", &result));
CPPUNIT_ASSERT_EQUAL(_("a\'aa\n\rb\vb\tb\\ccc\"ddd\b\fx"), result);

CPPUNIT_ASSERT(m_browser->RunScript("function f(a){return a;}f(123);", &result));
CPPUNIT_ASSERT_EQUAL(123, wxAtoi(result));

Expand Down

0 comments on commit 3d427a1

Please sign in to comment.