Skip to content

Commit

Permalink
Be a little more restrictive on special array variables in interopola…
Browse files Browse the repository at this point in the history
…tion.
  • Loading branch information
drgrice1 committed Oct 8, 2024
1 parent 0185194 commit e9f46cb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/text-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ export const isIdentifierChar = (ch: number) => ch == 95 /* _ */ || isASCIILette
export const isVariableStartChar = (ch: number) => ch == 95 /* _ */ || isASCIILetter(ch);

// !"$%&'()*+,-./0123456789:;<=>?@[\]`~
export const isSpecialVariableChar = (ch: number) =>
(ch >= 33 && ch != 35 && ch <= 64) || ch == 91 || ch == 92 || ch == 93 || ch == 96 || ch == 126;
// For arrays this is only used for interpolation and in that case only @$, @+, @-, and @1 .. @9 are allowed.
export const isSpecialVariableChar = (ch: number, arrayType = false) =>
arrayType
? ch == 36 || ch == 43 || ch == 45 || (ch >= 49 && ch <= 57)
: (ch >= 33 && ch != 35 && ch <= 64) || ch == 91 || ch == 92 || ch == 93 || ch == 96 || ch == 126;

/* 0-9, a-f, A-F */
export const isHex = (ch: number) => (ch >= 48 && ch <= 55) || (ch >= 97 && ch <= 102) || (ch >= 65 && ch <= 70);
Expand Down
2 changes: 1 addition & 1 deletion src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ export const interpolated = new ExternalTokenizer(
((input.next == 36 /* $ */ || input.next == 64) /* @ */ &&
(isVariableStartChar(input.peek(1)) ||
input.peek(1) == 123 /* { */ ||
(isSpecialVariableChar(input.peek(1)) &&
(isSpecialVariableChar(input.peek(1), input.next == 64 /* @ */) &&
(stack.context.nestLevel > 0 || input.peek(1) !== stack.context.endDelimiter))))
) {
break;
Expand Down

0 comments on commit e9f46cb

Please sign in to comment.