summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2022-01-10 12:40:35 -0800
committerGitHub <noreply@github.com>2022-01-10 12:40:35 -0800
commitc12de34c7d33b3ccf80f117edf78b5346bd00897 (patch)
tree741ea30521a130d463776a7cc7cce3bfede238bb /src
parent4952437ddc3d0ea07725493b14504868702f8967 (diff)
downloadbinaryen-c12de34c7d33b3ccf80f117edf78b5346bd00897.tar.gz
binaryen-c12de34c7d33b3ccf80f117edf78b5346bd00897.tar.bz2
binaryen-c12de34c7d33b3ccf80f117edf78b5346bd00897.zip
Escape \t as well as \n when writing JSON output. (#4437)
As it happens, this doesn't (normally) break the resulting EM_ASM or EM_JS strings because (IIUC) JS supports the tab literal inside of strings as well as "\t". However, it's better to preserve the original text so that it looks the same in the JS file as it did in the original source.
Diffstat (limited to 'src')
-rw-r--r--src/wasm/wasm-emscripten.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp
index 68c095111..33a92a6c4 100644
--- a/src/wasm/wasm-emscripten.cpp
+++ b/src/wasm/wasm-emscripten.cpp
@@ -79,6 +79,11 @@ std::string escape(std::string code) {
code = code.replace(curr, 2, "\\\\n");
curr += 3; // skip this one
}
+ curr = 0;
+ while ((curr = code.find("\\t", curr)) != std::string::npos) {
+ code = code.replace(curr, 2, "\\\\t");
+ curr += 3; // skip this one
+ }
// replace double quotes with escaped single quotes
curr = 0;
while ((curr = code.find('"', curr)) != std::string::npos) {