Skip to content

Commit

Permalink
fix: fix escaping JSON string values
Browse files Browse the repository at this point in the history
fixes #999
  • Loading branch information
RomanHotsiy committed Aug 7, 2019
1 parent 7849f7f commit 58cb20d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/utils/jsonToHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 58cb20d

Please sign in to comment.