Fix wxWebView::RunScript() with string containing backslashes

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 https://github.com/wxWidgets/wxWidgets/pull/741
This commit is contained in:
Maarten Bent
2018-02-21 21:51:36 +01:00
committed by Vadim Zeitlin
parent dd2d62c703
commit 3d427a1af1
2 changed files with 4 additions and 1 deletions

View File

@@ -38,7 +38,7 @@ public:
// Adds one escape level if there is a single quote, double quotes or // Adds one escape level if there is a single quote, double quotes or
// escape characters // 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"); escapeDoubleQuotes.Replace(&m_escapedCode,"\\1\\1\\\\\\2");
} }

View File

@@ -323,6 +323,9 @@ void WebTestCase::RunScript()
CPPUNIT_ASSERT(m_browser->RunScript("function f(a){return a;}f('Hello World!');", &result)); CPPUNIT_ASSERT(m_browser->RunScript("function f(a){return a;}f('Hello World!');", &result));
CPPUNIT_ASSERT_EQUAL(_("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(m_browser->RunScript("function f(a){return a;}f(123);", &result));
CPPUNIT_ASSERT_EQUAL(123, wxAtoi(result)); CPPUNIT_ASSERT_EQUAL(123, wxAtoi(result));