-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent invalid graphql field names from being created (#3994)
* fix: prevent invalid graphql field names from being created Note: This will currently transform (for example) `/*` into `_` so I'm not quite sure what the best course of action is to replace that Fixes #3487; Fixes #2925 * chore: revert yarn lock change * test: simplify tests * fix: dasherize after leading underscore
- Loading branch information
1 parent
db1590f
commit 14babb3
Showing
2 changed files
with
35 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const createKey = require(`../create-key`) | ||
|
||
describe(`createKey`, () => { | ||
it(`leaves valid strings as is`, () => { | ||
;[`01234`, `validstring`, `_hello`, `_`].forEach(input => { | ||
expect(createKey(input)).toBe(input) | ||
}) | ||
}) | ||
|
||
it(`replaces invalid characters`, () => { | ||
;[ | ||
[`/hello`, `_hello`], | ||
[`~/path/to/some/module`, `_-path-to-some-module`], | ||
[`/*`, `_-`], | ||
[`/*.js`, `_--js`], | ||
].forEach(([input, output]) => { | ||
expect(createKey(input)).toBe(output) | ||
}) | ||
}) | ||
|
||
it(`does not generate same key for different input`, () => { | ||
;[[`/*.js`, `*js`]].forEach(([one, two]) => { | ||
expect(createKey(one)).not.toBe(createKey(two)) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters