File tree Expand file tree Collapse file tree
ORLib/src/main/java/io/openremote/orlib/ui Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -949,14 +949,11 @@ open class OrMainActivity : Activity() {
949949 var jsonString = mapper.writeValueAsString(data)
950950 LOG .info(" Sending response to client: $jsonString " )
951951
952- // Double escape quotes (this is needed for browsers to be able to parse the response)
953- jsonString = jsonString.replace(" \\\" " , " \\\\\" " )
954-
955952 runOnUiThread {
956953 binding.webView.evaluateJavascript(
957954 String .format(
958955 " OpenRemoteConsole._handleProviderResponse('%s')" ,
959- jsonString
956+ jsonString.escapeForJavaScript()
960957 ), null
961958 )
962959 }
@@ -965,6 +962,16 @@ open class OrMainActivity : Activity() {
965962 }
966963 }
967964
965+ private fun String.escapeForJavaScript (): String {
966+ return this
967+ .replace(" \\ " , " \\\\ " )
968+ .replace(" '" , " \\ '" )
969+ .replace(" \" " , " \\\" " )
970+ .replace(" \n " , " \\ n" )
971+ .replace(" \r " , " \\ r" )
972+ .replace(" \t " , " \\ t" )
973+ }
974+
968975 private fun onConnectivityChanged (connectivity : Boolean ) {
969976 LOG .info(" Connectivity changed: $connectivity " )
970977 if (connectivity && ! webViewIsLoading && ! lastConnectivity) {
You can’t perform that action at this time.
0 commit comments