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

fix: Fix Safari 10–13 sticky regular expression quirks (#15)

* Fix constRe match for Safari

* Add quirk fix for floatPartRe

* Update operationDefinitionRe just in case

* Update character classes for names to be more precise

* Add changeset

authored by kitten.sh and committed by GitHub 1b2e92b1 44c47aaf

Changed files
+17 -5
.changeset
src
+5
.changeset/curvy-geese-hope.md
··· 1 + --- 2 + '@0no-co/graphql.web': patch 3 + --- 4 + 5 + Fix browser quirk occurring in Safari 10–13 causing sticky regular expressions in the parser to match when they shouldn't / match too eagerly.
+12 -5
src/parser.ts
··· 65 65 idx--; 66 66 } 67 67 68 - const nameRe = /[_\w][_\d\w]*/y; 68 + const nameRe = /[_A-Za-z]\w*/y; 69 69 function name(): ast.NameNode | undefined { 70 70 let match: string | undefined; 71 71 if ((match = advance(nameRe))) { ··· 76 76 } 77 77 } 78 78 79 - const constRe = /null|true|false/y; 80 - const variableRe = /\$[_\w][_\d\w]*/y; 79 + // NOTE(Safari10 Quirk): This needs to be wrapped in a non-capturing group 80 + const constRe = /(?:null|true|false)/y; 81 + 82 + const variableRe = /\$[_A-Za-z]\w*/y; 81 83 const intRe = /-?\d+/y; 82 - const floatPartRe = /(?:\.\d+)?(?:[eE][+-]?\d+)?/y; 84 + 85 + // NOTE(Safari10 Quirk): This cannot be further simplified 86 + const floatPartRe = /(?:\.\d+)?[eE][+-]?\d+|\.\d+/y; 87 + 83 88 const complexStringRe = /\\/g; 84 89 const blockStringRe = /"""(?:[\s\S]+(?="""))?"""/y; 85 90 const stringRe = /"(?:[^"\r\n]+)?"/y; ··· 413 418 } 414 419 } 415 420 416 - const operationDefinitionRe = /query|mutation|subscription/y; 421 + // NOTE(Safari10 Quirk): This *might* need to be wrapped in a group, but worked without it too 422 + const operationDefinitionRe = /(?:query|mutation|subscription)/y; 423 + 417 424 function operationDefinition(): ast.OperationDefinitionNode | undefined { 418 425 let _operation: string | undefined; 419 426 let _name: ast.NameNode | undefined;