Skip to content

Commit f5e73ab

Browse files
committed
Fix handling of escaped characters in string
1 parent b60d88f commit f5e73ab

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/compiler/commandLineParser.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,9 @@ namespace ts {
430430
let nextChar = (i + 1 < jsonText.length) ? jsonText.charAt(i + 1) : undefined;
431431
if (processingString) {
432432
if (currentChar === "\\"
433-
&& nextChar === "\"") {
434-
// Escaped quote consume the 2 characters
433+
&& nextChar !== undefined) {
434+
// Found an escaped character
435+
// consume the \ and the escaped char
435436
result += currentChar;
436437
result += nextChar;
437438
i += 1;

tests/cases/unittests/tsconfigParsing.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ module ts {
7777
}`, { config: { exclude: ["xx/*file.d.ts*/"] } });
7878
});
7979

80+
it("handles escaped characters in strings correctly", () => {
81+
assertParseResult(
82+
`{
83+
"exclude": [
84+
"xx\\"//files"
85+
]
86+
}`, { config: { exclude: ["xx\"//files"] } });
87+
88+
assertParseResult(
89+
`{
90+
"exclude": [
91+
"xx\\\\" // end of line comment
92+
]
93+
}`, { config: { exclude: ["xx\\"] } });
94+
});
95+
8096
it("returns object with error when json is invalid", () => {
8197
assertParseError("invalid");
8298
});

0 commit comments

Comments
 (0)