From 76aae8ce4235afbd2b79f99ee72698d75b40564f Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 9 Apr 2013 08:35:05 -0700 Subject: [PATCH] Escape path separator when using it as part of a regexp. [closes #233] Former-commit-id: 95d28187ee573ecc26e44f30cb5fb7457877dd06 --- build.js | 5 +---- build/minify.js | 2 +- build/mkdirp-sync.js | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/build.js b/build.js index 7c4635797..ab1e04f8a 100755 --- a/build.js +++ b/build.js @@ -25,7 +25,7 @@ var push = arrayRef.push; /** Used to detect the Node.js executable in command-line arguments */ - var reNode = RegExp('(?:^|' + path.sep + ')node(?:\\.exe)?$'); + var reNode = RegExp('(?:^|' + path.sep.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + ')node(?:\\.exe)?$'); /** Shortcut used to convert array-like objects to arrays */ var slice = arrayRef.slice; @@ -291,9 +291,6 @@ 'node' ]; - /** Add `path.sep` for older versions of Node.js */ - path.sep || (path.sep = process.platform == 'win32' ? '\\' : '/'); - /*--------------------------------------------------------------------------*/ /** diff --git a/build/minify.js b/build/minify.js index 88acedb21..50e421424 100755 --- a/build/minify.js +++ b/build/minify.js @@ -47,7 +47,7 @@ var mediaType = 'application/vnd.github.v3.raw'; /** Used to detect the Node.js executable in command-line arguments */ - var reNode = RegExp('(?:^|' + path.sep + ')node(?:\\.exe)?$'); + var reNode = RegExp('(?:^|' + path.sep.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + ')node(?:\\.exe)?$'); /** Used to reference parts of the blob href */ var location = (function() { diff --git a/build/mkdirp-sync.js b/build/mkdirp-sync.js index 19e0f915d..766cbb6a9 100755 --- a/build/mkdirp-sync.js +++ b/build/mkdirp-sync.js @@ -22,7 +22,7 @@ var sep = path.sep; // ensure relative paths are prefixed with `./` - if (!RegExp('^\\.?' + sep).test(dirname)) { + if (!RegExp('^\\.?' + sep.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).test(dirname)) { dirname = '.' + sep + dirname; } dirname.split(sep).reduce(function(currPath, segment) {