Skip to content

Commit

Permalink
fix: Fix typo causing complex string parsing to fail on subsequent ru…
Browse files Browse the repository at this point in the history
…ns (#31)

* Fix typo in complex string detection

Fix typo causing complex string detection not to trigger
correctly.

* Add changeset

* Add test
  • Loading branch information
kitten authored Aug 24, 2024
1 parent 3de5147 commit a7e16e5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/two-days-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@0no-co/graphql.web': patch
---

Fix typo causing complex string parsing to fail on subsequent runs.
17 changes: 17 additions & 0 deletions src/__tests__/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
Expand Down
2 changes: 1 addition & 1 deletion src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a7e16e5

Please sign in to comment.