Skip to content

Commit

Permalink
fix(gatsby-source-mongodb): sanitize name correctly (#11294)
Browse files Browse the repository at this point in the history
<!--
  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 <DSchau@users.noreply.github.com>
Co-authored-by: Ward Peeters <ward@coding-tech.com>
  • Loading branch information
3 people committed Mar 12, 2019
1 parent 5996a6b commit 731dd60
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
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())
}

0 comments on commit 731dd60

Please sign in to comment.