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

Commit 9e9467c

Browse files
crisptrutskiguybedford
authored andcommitted
Better path selection in .locate
* Comparing specificity for exact match made no sense * Comparing specificity for wildcard branch now * Measure specificity as number of slashes rather than absolute length
1 parent a9cf96e commit 9e9467c

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

.agignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/

src/system.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ function SystemLoader(options) {
169169

170170
// NB no specification provided for System.paths, used ideas discussed in https://github.com/jorendorff/js-loaders/issues/25
171171

172-
// most specific (longest) match wins
173-
var pathMatch = '', wildcard;
172+
// most specific (most number of slashes in path) match wins
173+
var pathMatch = '', wildcard, maxSlashCount = 0;
174174

175175
// check to see if we have a paths entry
176176
for (var p in this.paths) {
@@ -180,18 +180,21 @@ function SystemLoader(options) {
180180

181181
// exact path match
182182
if (pathParts.length == 1) {
183-
if (name == p && p.length > pathMatch.length) {
183+
if (name == p) {
184184
pathMatch = p;
185185
break;
186186
}
187187
}
188-
189188
// wildcard path match
190189
else {
191-
if (name.substr(0, pathParts[0].length) == pathParts[0] && name.substr(name.length - pathParts[1].length) == pathParts[1]) {
192-
pathMatch = p;
193-
wildcard = name.substr(pathParts[0].length, name.length - pathParts[1].length - pathParts[0].length);
194-
}
190+
var slashCount = p.match(/\//g).length;
191+
if (slashCount >= maxSlashCount &&
192+
name.substr(0, pathParts[0].length) == pathParts[0] &&
193+
name.substr(name.length - pathParts[1].length) == pathParts[1]) {
194+
maxSlashCount = slashCount;
195+
pathMatch = p;
196+
wildcard = name.substr(pathParts[0].length, name.length - pathParts[1].length - pathParts[0].length);
197+
}
195198
}
196199
}
197200

@@ -201,7 +204,7 @@ function SystemLoader(options) {
201204

202205
// percent encode just '#' in module names
203206
// according to https://github.com/jorendorff/js-loaders/blob/master/browser-loader.js#L238
204-
// we should encode everything, but it breaks for servers that don't expect it
207+
// we should encode everything, but it breaks for servers that don't expect it
205208
// like in (https://github.com/systemjs/systemjs/issues/168)
206209
if (isBrowser)
207210
outPath = outPath.replace(/#/g, '%23');

0 commit comments

Comments
 (0)