Skip to content

Commit

Permalink
fix: ensure graphql key is a valid graphql key value (#4000)
Browse files Browse the repository at this point in the history
* fix: ensure graphql key is a valid graphql key value

* chore: update comment
  • Loading branch information
DSchau authored and KyleAMathews committed Feb 14, 2018
1 parent 9c2a5ad commit 9269be2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions packages/gatsby/src/schema/__tests__/create-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ describe(`createKey`, () => {
it(`replaces invalid characters`, () => {
;[
[`/hello`, `_hello`],
[`~/path/to/some/module`, `_-path-to-some-module`],
[`/*`, `_-`],
[`/*.js`, `_--js`],
[`~/path/to/some/module`, `_xpathxtoxsomexmodule`],
[`/*`, `_x`],
[`/*.js`, `_xxjs`],
].forEach(([input, output]) => {
expect(createKey(input)).toBe(output)
})
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby/src/schema/create-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ module.exports = (key: string): string => {

const replaced = key.replace(nonAlphaNumericExpr, `_`)

// key is invalid; normalize with a leading underscore and dasherize rest
// key is invalid; normalize with leading underscore and rest with x
if (replaced.match(/^__/)) {
return replaced.replace(/_/g, (char, index) => (index === 0 ? `_` : `-`))
return replaced.replace(/_/g, (char, index) => (index === 0 ? `_` : `x`))
}

return replaced
Expand Down

0 comments on commit 9269be2

Please sign in to comment.