Skip to content

Commit

Permalink
hotfix: Fix empty string matching being too eager
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Jun 6, 2023
1 parent 80ef05b commit 29cbe5c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/strange-crabs-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@0no-co/graphql.web': patch
---

Fix empty string matches being too eager, e.g. `"", ""`
24 changes: 24 additions & 0 deletions src/__tests__/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,18 @@ describe('parseValue', () => {
value: 'x',
block: false,
});

expect(parseValue('"" ""')).toEqual({
kind: Kind.STRING,
value: '',
block: false,
});

expect(parseValue('" \\" " ""')).toEqual({
kind: Kind.STRING,
value: ' " ',
block: false,
});
});

it('parses objects', () => {
Expand Down Expand Up @@ -572,6 +584,18 @@ describe('parseValue', () => {
value: 'x',
block: true,
});

expect(parseValue('"""""" """"""')).toEqual({
kind: Kind.STRING,
value: '',
block: true,
});

expect(parseValue('""" \\""" """ """"""')).toEqual({
kind: Kind.STRING,
value: ' """ ',
block: true,
});
});

it('allows variables', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ const intRe = /-?\d+/y;
const floatPartRe = /(?:\.\d+)?[eE][+-]?\d+|\.\d+/y;

const complexStringRe = /\\/g;
const blockStringRe = /"""(?:[\s\S]*?[^\\])?"""/y;
const stringRe = /"(?:[^\r\n]*?[^\\])?"/y;
const blockStringRe = /"""(?:"""|(?:[\s\S]*?[^\\])""")/y;
const stringRe = /"(?:"|[^\r\n]*?[^\\]")/y;

function value(constant: true): ast.ConstValueNode;
function value(constant: boolean): ast.ValueNode;
Expand Down

0 comments on commit 29cbe5c

Please sign in to comment.