Skip to content
This repository was archived by the owner on Oct 9, 2020. It is now read-only.

Commit 2315f5f

Browse files
committed
fix up packageConfigPath regex
1 parent 3a4dacb commit 2315f5f

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

lib/utils.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function getAlias(loader, canonicalName) {
9696
bestAliasSubpath = '';
9797
bestAliasLength = alias.split('/').length;
9898
}
99-
else if (canonicalName.substr(0, mapped.length) == mapped &&
99+
else if (canonicalName.substr(0, mapped.length) == mapped &&
100100
(canonicalName.length == mapped.length || canonicalName[mapped.length] == '/')) {
101101
bestAlias = alias;
102102
bestAliasSubpath = canonicalName.substr(mapped.length);
@@ -189,7 +189,7 @@ function getCanonicalNamePlain(loader, normalized, isPlugin) {
189189

190190
// support trailing / in paths rules
191191
else if (curPath[curPath.length - 1] == '/' &&
192-
normalized.substr(0, curPath.length - 1) == curPath.substr(0, curPath.length - 1) &&
192+
normalized.substr(0, curPath.length - 1) == curPath.substr(0, curPath.length - 1) &&
193193
(normalized.length < curPath.length || normalized[curPath.length - 1] == curPath[curPath.length - 1])) {
194194
// first case is that canonicalize('src') = 'app' for 'app/': 'src/'
195195
return normalized.length < curPath.length ? p.substr(0, p.length - 1) : p + normalized.substr(curPath.length);
@@ -244,8 +244,7 @@ function createPkgConfigPathObj(path) {
244244
var length = Math.max(lastWildcard + 1, path.lastIndexOf('/'));
245245
return {
246246
length: length,
247-
// NB handle regex control character escapes or simply create a test function here
248-
regEx: new RegExp('^(' + path.substr(0, length).replace(/\*/g, '[^\\/]+') + ')(\\/|$)'),
247+
regEx: new RegExp('^(' + path.substr(0, length).replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '[^\\/]+') + ')(\\/|$)'),
249248
wildcard: lastWildcard != -1
250249
};
251250
}
@@ -373,4 +372,3 @@ exports.serializeCondition = serializeCondition;
373372
function serializeCondition(conditionObj) {
374373
return conditionObj.module + '|' + (conditionObj.negate ? '~' : '') + conditionObj.prop;
375374
}
376-

0 commit comments

Comments
 (0)