From 70faca17b68a3aa3e78a51a238d8090535ae1961 Mon Sep 17 00:00:00 2001 From: unarist Date: Tue, 26 Feb 2019 18:31:42 +0900 Subject: [PATCH] fix: escape backslashes in string literals (#823) Follow up for #822 and 04731656 (only escape quotes). --- src/utils/jsonToHtml.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/jsonToHtml.ts b/src/utils/jsonToHtml.ts index 414c3c76a8..abd4b14afe 100644 --- a/src/utils/jsonToHtml.ts +++ b/src/utils/jsonToHtml.ts @@ -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) { '' + - htmlEncode(escapeStringQuotes(value)) + + htmlEncode(escapeForStringLiteral(value)) + '' + 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');