diff --git a/modules/PathUtils.js b/modules/PathUtils.js index 8ea633755..959cbf5d7 100644 --- a/modules/PathUtils.js +++ b/modules/PathUtils.js @@ -1,3 +1,5 @@ +import escapeStringRegexp from 'escape-string-regexp'; + export const addLeadingSlash = path => path.charAt(0) === "/" ? path : "/" + path; @@ -5,7 +7,7 @@ export const stripLeadingSlash = path => path.charAt(0) === "/" ? path.substr(1) : path; export const hasBasename = (path, prefix) => - new RegExp("^" + prefix + "(\\/|\\?|#|$)", "i").test(path); + new RegExp("^" + escapeStringRegexp(prefix) + "(\\/|\\?|#|$)", "i").test(path); export const stripBasename = (path, prefix) => hasBasename(path, prefix) ? path.substr(prefix.length) : path; diff --git a/package.json b/package.json index fc2253b8b..2679292c6 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ }, "dependencies": { "babel-runtime": "^6.26.0", + "escape-string-regexp": "^1.0.5", "invariant": "^2.2.1", "loose-envify": "^1.2.0", "resolve-pathname": "^2.2.0",