Skip to content

Commit 85c8743

Browse files
authored
fix: Handle unexpected EOF for comments (end of input) (#62)
* Add extra EOF test cases * Fix unexpected EOF in comments * Add changeset * Apply lints
1 parent 51114d6 commit 85c8743

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

.changeset/mighty-frogs-push.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+
Handle trailing comment ending in EOF (end of input)

src/__tests__/parser.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ describe('parse', () => {
1010
expect(doc).toMatchSnapshot();
1111
});
1212

13+
it('parses unexpected EOF', () => {
14+
expect(() => parse('#')).toThrow();
15+
expect(() => parse(' ')).toThrow();
16+
expect(() => parse('q($')).toThrow();
17+
expect(() => parse('{x{')).toThrow();
18+
expect(() => parse('#\n')).toThrow();
19+
});
20+
1321
it('parses basic documents', () => {
1422
expect(() => parse('{')).toThrow();
1523
expect(() => parse('{}x ')).toThrow();

src/parser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ function ignored() {
6060
char === 65279 /*'\ufeff'*/;
6161
char = input.charCodeAt(idx++) | 0
6262
) {
63-
if (char === 35 /*'#'*/) while ((char = input.charCodeAt(idx++)) !== 10 && char !== 13);
63+
if (char === 35 /*'#'*/)
64+
while ((char = input.charCodeAt(idx++) | 0) && char !== 10 && char !== 13);
6465
}
6566
idx--;
6667
}

0 commit comments

Comments
 (0)