Bug 956567 - [prettify] Pretty print in the debugger produces invalid js. r=fitzgen

This commit is contained in:
Brion Vibber 2014-02-13 10:02:51 -05:00
parent 5d813f2a87
commit 070ae4ffe5
2 changed files with 9 additions and 2 deletions

View File

@ -463,6 +463,13 @@
return str.replace(/\n/g, "\\n");
}
/**
* Make sure that we put "\'" into the single-quoted output instead of raw single quotes.
*/
function sanitizeSingleQuotes(str) {
return str.replace(/\'/g, "\\'");
}
/**
* Add the given token to the pretty printed results.
*
@ -475,7 +482,7 @@
*/
function addToken(token, write, options) {
if (token.type.type == "string") {
write("'" + sanitizeNewlines(token.value) + "'",
write("'" + sanitizeSingleQuotes(sanitizeNewlines(token.value)) + "'",
token.startLoc.line,
token.startLoc.column);
} else {

View File

@ -179,7 +179,7 @@ var testCases = [
{
name: "String with quote",
input: "var foo = \"'\";\n",
output: "var foo = '\'';\n"
output: "var foo = '\\'';\n"
},
{