From f5e73ab8bf2d460c4f302f4d3aa286f9e0177f04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Arod?= Date: Thu, 29 Oct 2015 14:55:23 +0100 Subject: [PATCH] Fix handling of escaped characters in string --- src/compiler/commandLineParser.ts | 5 +++-- tests/cases/unittests/tsconfigParsing.ts | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index e5950db05b6..d69b91bd5b4 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -430,8 +430,9 @@ namespace ts { let nextChar = (i + 1 < jsonText.length) ? jsonText.charAt(i + 1) : undefined; if (processingString) { if (currentChar === "\\" - && nextChar === "\"") { - // Escaped quote consume the 2 characters + && nextChar !== undefined) { + // Found an escaped character + // consume the \ and the escaped char result += currentChar; result += nextChar; i += 1; diff --git a/tests/cases/unittests/tsconfigParsing.ts b/tests/cases/unittests/tsconfigParsing.ts index 3da1acb83c3..f48593b3169 100644 --- a/tests/cases/unittests/tsconfigParsing.ts +++ b/tests/cases/unittests/tsconfigParsing.ts @@ -77,6 +77,22 @@ module ts { }`, { config: { exclude: ["xx/*file.d.ts*/"] } }); }); + it("handles escaped characters in strings correctly", () => { + assertParseResult( + `{ + "exclude": [ + "xx\\"//files" + ] + }`, { config: { exclude: ["xx\"//files"] } }); + + assertParseResult( + `{ + "exclude": [ + "xx\\\\" // end of line comment + ] + }`, { config: { exclude: ["xx\\"] } }); + }); + it("returns object with error when json is invalid", () => { assertParseError("invalid"); });