Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Prevent empty index access ([])
Browse files Browse the repository at this point in the history
  • Loading branch information
g. nicholas d'andrea committed Apr 28, 2021
1 parent 0a505d7 commit a1a6f35
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/parse-mapping-lookup/src/grammar.ts
Expand Up @@ -41,8 +41,8 @@ export const definitions: Definitions<Forms> = {

value: ({ construct }) =>
noCharOf("]").pipe(
many(),
map(characters => construct({ contents: characters.join("") }))
then(noCharOf("]").pipe(many())),
map(([first, rest]) => construct({ contents: [first, ...rest].join("") }))
),

indexAccess: ({ construct, tie }) =>
Expand Down
6 changes: 6 additions & 0 deletions packages/parse-mapping-lookup/src/parser.spec.ts
Expand Up @@ -86,6 +86,12 @@ const testCases = [
position: 2
}
},
{
expression: `m[1].s[]`,
trace: {
position: 7
}
},
{
expression: `m[hex"deadbeef"]`,
value: expression({
Expand Down

0 comments on commit a1a6f35

Please sign in to comment.