Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure graphql key is a valid graphql key value #4000

Merged
merged 2 commits into from
Feb 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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