Skip to content

Commit

Permalink
fix: escape backslashes in string literals
Browse files Browse the repository at this point in the history
Follow up for #822 and 0473165 (only escape quotes).
  • Loading branch information
unarist committed Feb 26, 2019
1 parent 3ce5bff commit cb76543
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 @@ -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) {
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit cb76543

Please sign in to comment.