Skip to content

Commit 29cbe5c

Browse files
committed
hotfix: Fix empty string matching being too eager
1 parent 80ef05b commit 29cbe5c

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

.changeset/strange-crabs-love.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@0no-co/graphql.web': patch
3+
---
4+
5+
Fix empty string matches being too eager, e.g. `"", ""`

src/__tests__/parser.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,18 @@ describe('parseValue', () => {
490490
value: 'x',
491491
block: false,
492492
});
493+
494+
expect(parseValue('"" ""')).toEqual({
495+
kind: Kind.STRING,
496+
value: '',
497+
block: false,
498+
});
499+
500+
expect(parseValue('" \\" " ""')).toEqual({
501+
kind: Kind.STRING,
502+
value: ' " ',
503+
block: false,
504+
});
493505
});
494506

495507
it('parses objects', () => {
@@ -572,6 +584,18 @@ describe('parseValue', () => {
572584
value: 'x',
573585
block: true,
574586
});
587+
588+
expect(parseValue('"""""" """"""')).toEqual({
589+
kind: Kind.STRING,
590+
value: '',
591+
block: true,
592+
});
593+
594+
expect(parseValue('""" \\""" """ """"""')).toEqual({
595+
kind: Kind.STRING,
596+
value: ' """ ',
597+
block: true,
598+
});
575599
});
576600

577601
it('allows variables', () => {

src/parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ const intRe = /-?\d+/y;
8686
const floatPartRe = /(?:\.\d+)?[eE][+-]?\d+|\.\d+/y;
8787

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

9292
function value(constant: true): ast.ConstValueNode;
9393
function value(constant: boolean): ast.ValueNode;

0 commit comments

Comments
 (0)