From 92d6f3a093eb36d1f8dae90b0d8fafe741d5f540 Mon Sep 17 00:00:00 2001 From: Ivan <6350992+bivant@users.noreply.github.com> Date: Mon, 23 Sep 2019 16:52:25 +0300 Subject: [PATCH 1/2] Escape most of special symbols on Android, double quotes on iOS --- Code.gs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Code.gs b/Code.gs index 66bde0c..654dba4 100644 --- a/Code.gs +++ b/Code.gs @@ -192,6 +192,13 @@ function makeAndroidString(object, textIndex, options) { exportString += "\t" + '' + "\n"; prevIdentifier = ""; } + + text = text.replace(/\n/g, "\\n"); + text = text.replace(/&/g, "&"); + text = text.replace(/\'/g, "\\'"); + text = text.replace(//g, ">"); + text = text.replace(/"/g, "\\\""); if(identifier.indexOf("[]")>0) { @@ -199,7 +206,7 @@ function makeAndroidString(object, textIndex, options) { exportString += "\t" + '' + "\n"; } - exportString += "\t\t"+''+o.text+'' + "\n"; + exportString += "\t\t"+''+text+'' + "\n"; prevIdentifier = identifier; } else { @@ -261,6 +268,8 @@ function makeIosString(object, textIndex, options) { continue; } + text = text.replace(/"/g, "\\\""); + exportString += '"' + identifier + '" = "' + text + "\";\n"; } From 0a90e3e5db5b36a20e22e308175513e333f0ca31 Mon Sep 17 00:00:00 2001 From: Ivan <6350992+bivant@users.noreply.github.com> Date: Tue, 24 Sep 2019 20:38:15 +0300 Subject: [PATCH 2/2] Prevent error on symbols escape attempt if value/translation is number --- Code.gs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Code.gs b/Code.gs index 654dba4..a4c8a7f 100644 --- a/Code.gs +++ b/Code.gs @@ -193,12 +193,14 @@ function makeAndroidString(object, textIndex, options) { prevIdentifier = ""; } - text = text.replace(/\n/g, "\\n"); - text = text.replace(/&/g, "&"); - text = text.replace(/\'/g, "\\'"); - text = text.replace(//g, ">"); - text = text.replace(/"/g, "\\\""); + if(typeof text === 'string') { + text = text.replace(/\n/g, "\\n"); + text = text.replace(/&/g, "&"); + text = text.replace(/\'/g, "\\'"); + text = text.replace(//g, ">"); + text = text.replace(/"/g, "\\\""); + } if(identifier.indexOf("[]")>0) { @@ -268,7 +270,9 @@ function makeIosString(object, textIndex, options) { continue; } - text = text.replace(/"/g, "\\\""); + if(typeof text === 'string') { + text = text.replace(/"/g, "\\\""); + } exportString += '"' + identifier + '" = "' + text + "\";\n"; }