Skip to content

Commit

Permalink
fix: escape quotes in string values
Browse files Browse the repository at this point in the history
fixes #882
  • Loading branch information
RomanHotsiy committed Feb 26, 2019
1 parent 3659a75 commit 0473165
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/utils/jsonToHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ function htmlEncode(t) {
: '';
}

function escapeStringQuotes(str: string) {
return str.replace(/"/g, '\\"');
}

function decorateWithSpan(value, className) {
return '<span class="' + className + '">' + htmlEncode(value) + '</span>';
}
Expand Down Expand Up @@ -53,11 +57,11 @@ function valueToHTML(value) {
'<a href="' +
value +
'">' +
htmlEncode(value) +
htmlEncode(escapeStringQuotes(value)) +
'</a>' +
decorateWithSpan('"', 'token string');
} else {
output += decorateWithSpan('"' + value + '"', 'token string');
output += decorateWithSpan('"' + escapeStringQuotes(value) + '"', 'token string');
}
} else if (valueType === 'boolean') {
output += decorateWithSpan(value, 'token boolean');
Expand Down

0 comments on commit 0473165

Please sign in to comment.