Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/recipe/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,19 @@ function parseValue(sourceName: string, text: string, offset: number): Canonical
(value.startsWith('"') && value.endsWith('"'))
|| (value.startsWith("'") && value.endsWith("'"))
) {
return value.slice(1, -1);
const quote = value[0] as "\"" | "'";
let unescaped = "";
for (let index = 1; index < value.length - 1; index += 1) {
const character = value[index]!;
const next = value[index + 1];
if (character === "\\" && (next === quote || next === "\\")) {
unescaped += next;
index += 1;
continue;
}
unescaped += character;
}
return unescaped;
}
return value;
}
Expand Down
17 changes: 17 additions & 0 deletions packages/recipe/test/source-closure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,23 @@ test("quoted Recipe values may contain Prompt punctuation without changing SVS s
assert.equal(sheet.recipes[0]?.value.properties.text, "first; second } /* literal */");
});

test("quoted Recipe values unescape the escaped quote and backslash the scanners honor", () => {
const sheet = parseRecipe(
"escape.svs",
`<sheet version="1">
caption.host {
text: "He said \\"hi\\" twice";
note: "path C:\\\\caps ends here";
aside: 'It\\'s minimal';
}
</sheet>`,
);
const properties = sheet.recipes[0]?.value.properties;
assert.equal(properties.text, 'He said "hi" twice');
assert.equal(properties.note, "path C:\\caps ends here");
assert.equal(properties.aside, "It's minimal");
});

test("quoted Recipe values may contain the sheet closing text without ending the document", () => {
const sheet = parseRecipe(
"literal-close.svs",
Expand Down