Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix typo causing complex string parsing to fail on subsequent runs #31

Merged
merged 3 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading