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(gatsby-source-mongodb): sanitize name correctly #11294

Merged
merged 8 commits into from
Mar 12, 2019
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
7 changes: 7 additions & 0 deletions packages/gatsby-source-mongodb/src/__tests__/sanitize-name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const sanitizeName = require(`../sanitize-name`)

it(`removes unsupported characters from name`, () => {
const name = `one-two-three`
const output = sanitizeName(name)
expect(output).not.toContain(`-`)
})
5 changes: 1 addition & 4 deletions packages/gatsby-source-mongodb/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const MongoClient = require(`mongodb`).MongoClient
const crypto = require(`crypto`)
const prepareMappingChildNode = require(`./mapping`)
const sanitizeName = require(`./sanitize-name`)
const queryString = require(`query-string`)

exports.sourceNodes = (
Expand Down Expand Up @@ -130,10 +131,6 @@ function createNodes(
})
}

function sanitizeName(s) {
return s.replace(/[^_a-zA-Z0-9]/, ``).replace(/\b\w/g, l => l.toUpperCase())
}

function getConnectionExtraParams(extraParams) {
let connectionSuffix
if (extraParams) {
Expand Down
3 changes: 3 additions & 0 deletions packages/gatsby-source-mongodb/src/sanitize-name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function sanitizeName(s) {
return s.replace(/[^_a-zA-Z0-9]/g, ``).replace(/\b\w/g, l => l.toUpperCase())
}