fix: fix escaping JSON string values

fixes #999
This commit is contained in:
Roman Hotsiy 2019-08-07 12:02:25 +03:00
parent 7849f7f6b7
commit 58cb20d4b2
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0

View File

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