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

fix: Handle unexpected EOF for comments (end of input) (#62)

* Add extra EOF test cases

* Fix unexpected EOF in comments

* Add changeset

* Apply lints

authored by kitten.sh and committed by GitHub 85c87432 51114d6c

Changed files
+15 -1
.changeset
src
+5
.changeset/mighty-frogs-push.md
··· 1 + --- 2 + "@0no-co/graphql.web": patch 3 + --- 4 + 5 + Handle trailing comment ending in EOF (end of input)
+8
src/__tests__/parser.test.ts
··· 10 10 expect(doc).toMatchSnapshot(); 11 11 }); 12 12 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 + 13 21 it('parses basic documents', () => { 14 22 expect(() => parse('{')).toThrow(); 15 23 expect(() => parse('{}x ')).toThrow();
+2 -1
src/parser.ts
··· 60 60 char === 65279 /*'\ufeff'*/; 61 61 char = input.charCodeAt(idx++) | 0 62 62 ) { 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); 64 65 } 65 66 idx--; 66 67 }