From 766a6570228d29dd3e7b695937e76401b7b93ee6 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Sat, 24 Aug 2024 11:17:57 +0100 Subject: [PATCH 1/3] Fix typo in complex string detection Fix typo causing complex string detection not to trigger correctly. --- src/parser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parser.ts b/src/parser.ts index 25f1b7d..ce339c9 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -105,7 +105,7 @@ type ValueExec = RegExpExecArray & { [Prop in ValueGroup]: string | undefined; }; -const complexStringRe = /\\/g; +const complexStringRe = /\\/; function value(constant: true): ast.ConstValueNode; function value(constant: boolean): ast.ValueNode; From eddf4abd2937571a8f9ae308327cb4651b75e36d Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Sat, 24 Aug 2024 11:18:41 +0100 Subject: [PATCH 2/3] Add changeset --- .changeset/two-days-nail.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/two-days-nail.md diff --git a/.changeset/two-days-nail.md b/.changeset/two-days-nail.md new file mode 100644 index 0000000..bd85dd7 --- /dev/null +++ b/.changeset/two-days-nail.md @@ -0,0 +1,5 @@ +--- +'@0no-co/graphql.web': patch +--- + +Fix typo causing complex string parsing to fail on subsequent runs. From 5608597aa8895edd577958e6affd1724d0497534 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Sat, 24 Aug 2024 11:22:57 +0100 Subject: [PATCH 3/3] Add test --- src/__tests__/parser.test.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/__tests__/parser.test.ts b/src/__tests__/parser.test.ts index d12f1c8..8e5d1be 100644 --- a/src/__tests__/parser.test.ts +++ b/src/__tests__/parser.test.ts @@ -73,6 +73,23 @@ describe('parse', () => { }).toThrow(); }); + it('parses escaped characters', () => { + let ast = parse(` + { field(arg: "Has another \\\\x sequence.") } + `); + expect(ast).toHaveProperty( + 'definitions.0.selectionSet.selections.0.arguments.0.value.value', + 'Has another \\x sequence.' + ); + ast = parse(` + { field(arg: "Has a \\\\x sequence.") } + `); + expect(ast).toHaveProperty( + 'definitions.0.selectionSet.selections.0.arguments.0.value.value', + 'Has a \\x sequence.' + ); + }); + it('parses multi-byte characters', () => { // Note: \u0A0A could be naively interpreted as two line-feed chars. const ast = parse(`