mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-22 16:46:34 +03:00
fix: escape backslashes in string literals (#823)
Follow up for #822 and 04731656
(only escape quotes).
This commit is contained in:
parent
3ce5bff438
commit
70faca17b6
|
@ -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');
|
||||
|
|
Loading…
Reference in New Issue
Block a user