Skip to content

Commit

Permalink
fix: ignore invalid escape sequences in doc text
Browse files Browse the repository at this point in the history
  • Loading branch information
rmhartog committed May 22, 2024
1 parent a97dc2d commit c1e853c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
28 changes: 27 additions & 1 deletion packages/compiler/src/core/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,33 @@ export function createScanner(

function getDocTextValue(): string {
if (tokenFlags & TokenFlags.Escaped) {
return unescapeString(tokenPosition, position);
let start = tokenPosition;
const end = position;

let result = "";
let pos = start;

while (pos < end) {
const ch = input.charCodeAt(pos);
if (ch !== CharCode.Backslash) {
pos++;
continue;
}

result += input.substring(start, pos);
switch (input.charCodeAt(pos + 1)) {
case CharCode.At:
result += "@";
break;
default:
result += input.substring(pos, pos + 2);
}
pos += 2;
start = pos;
}

result += input.substring(start, pos);
return result;
} else {
return input.substring(tokenPosition, position);
}
Expand Down
24 changes: 12 additions & 12 deletions packages/compiler/test/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1045,18 +1045,18 @@ describe("compiler: parser", () => {
strictEqual(
docs[0].content[0].text,
"This one has a `code span` and a code fence and it spreads over\n" +
"more than one line.\n\n" +
"```\n" +
"This is not a @tag because we're in a code fence.\n" +
" This is indented code.\n" +
"```\n\n" +
"```\n" +
"This code fence is glued\n" +
"to the stars\n" +
"```\n\n" +
"`This is not a @tag either because we're in a code span`.\n" +
"\n" +
"This is not a @tag because it is escaped."
"more than one line.\n\n" +
"```\n" +
"This is not a @tag because we're in a code fence.\n" +
" This is indented code.\n" +
"```\n\n" +
"```\n" +
"This code fence is glued\n" +
"to the stars\n" +
"```\n\n" +
"`This is not a @tag either because we're in a code span`.\n" +
"\n" +
"This is not a @tag because it is escaped."
);
strictEqual(docs[0].tags.length, 6);
const [xParam, yParam, tTemplate, uTemplate, returns, pretend] = docs[0].tags;
Expand Down

0 comments on commit c1e853c

Please sign in to comment.