Skip to content

Commit 731dd60

Browse files
harshil1712DSchauwardpeet
committed
fix(gatsby-source-mongodb): sanitize name correctly (#11294)
<!-- Have any questions? Check out the contributing docs at https://gatsby.app/contribute, or ask in this Pull Request and a Gatsby maintainer will be happy to help :) --> ## Description This is the PR for issue #11277. It fixes the sanitizeName error. <!-- Write a brief description of the changes introduced by this PR --> ## Related Issues Related to #11277 <!-- Link to the issue that is fixed by this PR (if there is one) e.g. Fixes #1234, Addresses #1234, Related to #1234, etc. --> Co-authored-by: Dustin Schau <[email protected]> Co-authored-by: Ward Peeters <[email protected]>
1 parent 5996a6b commit 731dd60

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const sanitizeName = require(`../sanitize-name`)
2+
3+
it(`removes unsupported characters from name`, () => {
4+
const name = `one-two-three`
5+
const output = sanitizeName(name)
6+
expect(output).not.toContain(`-`)
7+
})

packages/gatsby-source-mongodb/src/gatsby-node.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const MongoClient = require(`mongodb`).MongoClient
22
const crypto = require(`crypto`)
33
const prepareMappingChildNode = require(`./mapping`)
4+
const sanitizeName = require(`./sanitize-name`)
45
const queryString = require(`query-string`)
56

67
exports.sourceNodes = (
@@ -130,10 +131,6 @@ function createNodes(
130131
})
131132
}
132133

133-
function sanitizeName(s) {
134-
return s.replace(/[^_a-zA-Z0-9]/, ``).replace(/\b\w/g, l => l.toUpperCase())
135-
}
136-
137134
function getConnectionExtraParams(extraParams) {
138135
let connectionSuffix
139136
if (extraParams) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = function sanitizeName(s) {
2+
return s.replace(/[^_a-zA-Z0-9]/g, ``).replace(/\b\w/g, l => l.toUpperCase())
3+
}

0 commit comments

Comments
 (0)