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