From 1e3740efdc3bed63fef073381daa56640cb5be39 Mon Sep 17 00:00:00 2001 From: Dustin Schau Date: Mon, 12 Feb 2018 20:54:58 -0800 Subject: [PATCH 1/2] fix: ensure graphql key is a valid graphql key value --- packages/gatsby/src/schema/__tests__/create-key.js | 6 +++--- packages/gatsby/src/schema/create-key.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/gatsby/src/schema/__tests__/create-key.js b/packages/gatsby/src/schema/__tests__/create-key.js index da6484dda1888..2de5c7a3915e3 100644 --- a/packages/gatsby/src/schema/__tests__/create-key.js +++ b/packages/gatsby/src/schema/__tests__/create-key.js @@ -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) }) diff --git a/packages/gatsby/src/schema/create-key.js b/packages/gatsby/src/schema/create-key.js index 4cb78499f5552..5b49a6d0c0aaf 100644 --- a/packages/gatsby/src/schema/create-key.js +++ b/packages/gatsby/src/schema/create-key.js @@ -18,7 +18,7 @@ module.exports = (key: string): string => { // key is invalid; normalize with a leading underscore and dasherize rest if (replaced.match(/^__/)) { - return replaced.replace(/_/g, (char, index) => (index === 0 ? `_` : `-`)) + return replaced.replace(/_/g, (char, index) => (index === 0 ? `_` : `x`)) } return replaced From 21040f05403eee865aafc51a5864c9fbea91fd02 Mon Sep 17 00:00:00 2001 From: Dustin Schau Date: Mon, 12 Feb 2018 20:58:29 -0800 Subject: [PATCH 2/2] chore: update comment --- packages/gatsby/src/schema/create-key.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby/src/schema/create-key.js b/packages/gatsby/src/schema/create-key.js index 5b49a6d0c0aaf..ab54c3828f5b0 100644 --- a/packages/gatsby/src/schema/create-key.js +++ b/packages/gatsby/src/schema/create-key.js @@ -16,7 +16,7 @@ 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 ? `_` : `x`)) }