Including %22 in Android WebView postMessage payload results in SyntaxError #19611
Labels
Component: WebView
Related to the WebView component.
Platform: Android
Android applications.
Platform: Linux
Building on Linux.
Resolution: Locked
This issue was locked by the bot.
Environment
Environment:
OS: Linux 4.16
Node: 9.11.1
Yarn: 1.6.0
npm: 6.0.1
Watchman: 4.9.0
Xcode: N/A
Android Studio: Not Found
Packages: (wanted => installed)
react: 16.3.1 => 16.3.1
react-native: 0.55.4 => 0.55.4
Description
On Android 4.4 and above, WebView's
loadUrl
performs URL decoding on the string passed in. This results in a%22
being decoded to"
prior to the javascript being executed. The extra un-escaped quote results in the javascript containing a syntax error, thus failing to execute.There are (at least) two past and present PRs that have sought to address this in
injectedJavascript
, by usingevaluateJavascript
on 4.4 and above:#12321
#9945
I can confirm that changing ReactWebViewmanager's
receiveCommand
to callroot.evaluateJavascript
results in the expected behavior.Steps to Reproduce
react-native run-android
.postMessage with %22
button.Expected Behavior
Text inside the WebView should change from "test" to "success". Expected behavior can be observed by pressing the
postMessage without %22 button
.Actual Behavior
Text inside the WebView does not change.
Inspecting the WebView with Chrome reveals the following error:
Uncaught SyntaxError: Invalid or unexpected token
e.g. after clicking the button 4 times:
The text was updated successfully, but these errors were encountered: