fix: escape backslashes in string literals (#823)

Follow up for #822 and 04731656 (only escape quotes).
This commit is contained in:
unarist 2019-02-26 18:31:42 +09:00 committed by Roman Hotsiy
parent 3ce5bff438
commit 70faca17b6

View File

@ -21,8 +21,8 @@ function htmlEncode(t) {
: ''; : '';
} }
function escapeStringQuotes(str: string) { function escapeForStringLiteral(str: string) {
return str.replace(/"/g, '\\"'); return str.replace(/([\\"])/g, '\\$1');
} }
function decorateWithSpan(value, className) { function decorateWithSpan(value, className) {
@ -57,11 +57,11 @@ function valueToHTML(value) {
'<a href="' + '<a href="' +
value + value +
'">' + '">' +
htmlEncode(escapeStringQuotes(value)) + htmlEncode(escapeForStringLiteral(value)) +
'</a>' + '</a>' +
decorateWithSpan('"', 'token string'); decorateWithSpan('"', 'token string');
} else { } else {
output += decorateWithSpan('"' + escapeStringQuotes(value) + '"', 'token string'); output += decorateWithSpan('"' + escapeForStringLiteral(value) + '"', 'token string');
} }
} else if (valueType === 'boolean') { } else if (valueType === 'boolean') {
output += decorateWithSpan(value, 'token boolean'); output += decorateWithSpan(value, 'token boolean');