mirror of
https://github.com/Redocly/redoc.git
synced 2025-07-10 08:12:23 +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) {
|
function escapeForStringLiteral(str: string) {
|
||||||
return str.replace(/"/g, '\\"');
|
return str.replace(/([\\"])/g, '\\$1');
|
||||||
}
|
}
|
||||||
|
|
||||||
function decorateWithSpan(value, className) {
|
function decorateWithSpan(value, className) {
|
||||||
|
@ -57,11 +57,11 @@ function valueToHTML(value) {
|
||||||
'<a href="' +
|
'<a href="' +
|
||||||
value +
|
value +
|
||||||
'">' +
|
'">' +
|
||||||
htmlEncode(escapeStringQuotes(value)) +
|
htmlEncode(escapeForStringLiteral(value)) +
|
||||||
'</a>' +
|
'</a>' +
|
||||||
decorateWithSpan('"', 'token string');
|
decorateWithSpan('"', 'token string');
|
||||||
} else {
|
} else {
|
||||||
output += decorateWithSpan('"' + escapeStringQuotes(value) + '"', 'token string');
|
output += decorateWithSpan('"' + escapeForStringLiteral(value) + '"', 'token string');
|
||||||
}
|
}
|
||||||
} else if (valueType === 'boolean') {
|
} else if (valueType === 'boolean') {
|
||||||
output += decorateWithSpan(value, 'token boolean');
|
output += decorateWithSpan(value, 'token boolean');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user