Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 8b8c474

Browse files
committed
handle already-quoted double-quotes in EM_ASM
1 parent 197e296 commit 8b8c474

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/Target/JSBackend/JSBackend.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,13 @@ namespace {
394394
// replace double quotes with escaped single quotes
395395
curr = 0;
396396
while ((curr = code.find('"', curr)) != std::string::npos) {
397-
code = code.replace(curr, 1, "\\" "\"");
398-
curr += 2; // skip this one
397+
if (curr == 0 || code[curr-1] != '\\') {
398+
code = code.replace(curr, 1, "\\" "\"");
399+
curr += 2; // skip this one
400+
} else { // already escaped, escape the slash as well
401+
code = code.replace(curr, 1, "\\" "\\" "\"");
402+
curr += 3; // skip this one
403+
}
399404
}
400405
}
401406
if (AsmConsts.count(code) > 0) return AsmConsts[code];

0 commit comments

Comments
 (0)