From 3d427a1af1d1c4e2c22972b1c27ce3088c7fa708 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Wed, 21 Feb 2018 21:51:36 +0100 Subject: [PATCH] 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 --- include/wx/private/jsscriptwrapper.h | 2 +- tests/controls/webtest.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/wx/private/jsscriptwrapper.h b/include/wx/private/jsscriptwrapper.h index 7fd036302a4d..4bd061197ea9 100644 --- a/include/wx/private/jsscriptwrapper.h +++ b/include/wx/private/jsscriptwrapper.h @@ -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"); } diff --git a/tests/controls/webtest.cpp b/tests/controls/webtest.cpp index b6742e663b05..a71db74ef793 100644 --- a/tests/controls/webtest.cpp +++ b/tests/controls/webtest.cpp @@ -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));