Mirror: The spec-compliant minimum of client-side GraphQL.

hotfix: Fix empty string matching being too eager

Changed files
+31 -2
.changeset
src
+5
.changeset/strange-crabs-love.md
···
+
---
+
'@0no-co/graphql.web': patch
+
---
+
+
Fix empty string matches being too eager, e.g. `"", ""`
+24
src/__tests__/parser.test.ts
···
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', () => {
···
expect(parseValue('"""x""" """x"""')).toEqual({
kind: Kind.STRING,
value: 'x',
+
block: true,
+
});
+
+
expect(parseValue('"""""" """"""')).toEqual({
+
kind: Kind.STRING,
+
value: '',
+
block: true,
+
});
+
+
expect(parseValue('""" \\""" """ """"""')).toEqual({
+
kind: Kind.STRING,
+
value: ' """ ',
block: true,
});
});
+2 -2
src/parser.ts
···
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;