Skip to content

Commit 61e0212

Browse files
committed
fixed global RegExp issue
webpack#433
1 parent 04121c8 commit 61e0212

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

lib/TemplatedPathPlugin.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ var REGEXP_HASH = /\[hash(?::(\d+))?\]/gi,
1111
REGEXP_QUERY = /\[query\]/gi,
1212
REGEXP_FILEBASE = /\[filebase\]/gi;
1313

14+
// Using global RegExp for .test is dangerous
15+
// We use a normal RegExp instead of .test
16+
var REGEXP_HASH_FOR_TEST = new RegExp(REGEXP_HASH.source, "i"),
17+
REGEXP_CHUNKHASH_FOR_TEST = new RegExp(REGEXP_CHUNKHASH.source, "i"),
18+
REGEXP_NAME_FOR_TEST = new RegExp(REGEXP_NAME.source, "i");
19+
1420
// Backwards compatibility; expose regexes on Template object
1521
var Template = require("./Template");
1622
Template.REGEXP_HASH = REGEXP_HASH;
@@ -79,13 +85,13 @@ TemplatedPathPlugin.prototype.apply = function(compiler) {
7985
var publicPath = outputOptions.publicPath || "";
8086
var filename = outputOptions.filename || "";
8187
var chunkFilename = outputOptions.chunkFilename || "";
82-
if(REGEXP_HASH.test(publicPath) || REGEXP_CHUNKHASH.test(publicPath) || REGEXP_NAME.test(publicPath))
88+
if(REGEXP_HASH_FOR_TEST.test(publicPath) || REGEXP_CHUNKHASH_FOR_TEST.test(publicPath) || REGEXP_NAME_FOR_TEST.test(publicPath))
8389
return true;
84-
if(REGEXP_HASH.test(filename))
90+
if(REGEXP_HASH_FOR_TEST.test(filename))
8591
return true;
86-
if(REGEXP_HASH.test(chunkFilename) || REGEXP_CHUNKHASH.test(chunkFilename) || REGEXP_NAME.test(chunkFilename))
92+
if(REGEXP_HASH_FOR_TEST.test(chunkFilename) || REGEXP_CHUNKHASH_FOR_TEST.test(chunkFilename) || REGEXP_NAME_FOR_TEST.test(chunkFilename))
8793
return true;
88-
if(REGEXP_HASH.test(paths.join("|")))
94+
if(REGEXP_HASH_FOR_TEST.test(paths.join("|")))
8995
return true;
9096
});
9197
});

0 commit comments

Comments
 (0)