From 5bb3fd2f1964017a832c1ecbde5dafa94382b3e2 Mon Sep 17 00:00:00 2001 From: Andrew Hyndman Date: Wed, 18 Jul 2018 19:13:38 -0700 Subject: [PATCH] Escape basename before interpreting as Regex --- modules/PathUtils.js | 4 +++- package.json | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) 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",