mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 01:49:57 -05:00
Fix handling of escaped characters in string
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user