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

Commit 985fb7a

Browse files
committed
correct percent encoding
1 parent 099ad15 commit 985fb7a

File tree

5 files changed

+32
-32
lines changed

5 files changed

+32
-32
lines changed

dist/es6-module-loader-sans-promises.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,8 @@ function logloads(loads) {
10481048
var traceur;
10491049
Loader.prototype.parse = function(load) {
10501050
if (!traceur) {
1051-
if (typeof window == 'undefined')
1051+
if (typeof window == 'undefined' &&
1052+
typeof WorkerGlobalScope == 'undefined')
10521053
traceur = require('traceur');
10531054
else if (__global.traceur)
10541055
traceur = __global.traceur;
@@ -1140,7 +1141,8 @@ function logloads(loads) {
11401141

11411142
(function (global) {
11421143

1143-
var isBrowser = typeof window != 'undefined';
1144+
var isWorker = typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
1145+
var isBrowser = typeof window != 'undefined' && !isWorker;
11441146
var Loader = global.Reflect && global.Reflect.Loader || require('./loader');
11451147
var Promise = global.Promise || require('when/es6-shim/Promise');
11461148

@@ -1187,7 +1189,7 @@ function logloads(loads) {
11871189
}
11881190

11891191
var fetchTextFromURL;
1190-
if (isBrowser) {
1192+
if (isBrowser || isWorker) {
11911193
fetchTextFromURL = function(url, fulfill, reject) {
11921194
var xhr = new XMLHttpRequest();
11931195
var sameDomain = true;
@@ -1240,7 +1242,7 @@ function logloads(loads) {
12401242
}
12411243

12421244
var System = new Loader({
1243-
global: isBrowser ? window : global,
1245+
global: isBrowser ? window : (isWorker ? self : global),
12441246
strict: true,
12451247
normalize: function(name, parentName, parentAddress) {
12461248
if (typeof name != 'string')
@@ -1328,14 +1330,12 @@ function logloads(loads) {
13281330
if (wildcard)
13291331
outPath = outPath.replace('*', wildcard);
13301332

1331-
// percent encode each path part
1332-
if (isBrowser) {
1333-
var outParts = outPath.split('/');
1334-
for (var i = 0, l = outParts.length; i < l; i++) {
1335-
outParts[i] = encodeURIComponent(outParts[i]);
1336-
}
1337-
outPath = outParts.join('/');
1338-
}
1333+
// percent encode just '#' in module names
1334+
// according to https://github.com/jorendorff/js-loaders/blob/master/browser-loader.js#L238
1335+
// we should encode everything, but it breaks for servers that don't expect it
1336+
// like in (https://github.com/systemjs/systemjs/issues/168)
1337+
if (isBrowser)
1338+
outPath = outPath.replace(/#/g, '%23');
13391339

13401340
return toAbsoluteURL(this.baseURL, outPath);
13411341
},
@@ -1349,8 +1349,8 @@ function logloads(loads) {
13491349
},
13501350
});
13511351

1352-
if (isBrowser) {
1353-
var href = window.location.href.split('#')[0].split('?')[0];
1352+
if (isBrowser || isWorker) {
1353+
var href = global.location.href.split('#')[0].split('?')[0];
13541354
System.baseURL = href.substring(0, href.lastIndexOf('/') + 1);
13551355
}
13561356
else {

dist/es6-module-loader-sans-promises.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/es6-module-loader.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,8 @@ function logloads(loads) {
22112211
var traceur;
22122212
Loader.prototype.parse = function(load) {
22132213
if (!traceur) {
2214-
if (typeof window == 'undefined')
2214+
if (typeof window == 'undefined' &&
2215+
typeof WorkerGlobalScope == 'undefined')
22152216
traceur = require('traceur');
22162217
else if (__global.traceur)
22172218
traceur = __global.traceur;
@@ -2303,7 +2304,8 @@ function logloads(loads) {
23032304

23042305
(function (global) {
23052306

2306-
var isBrowser = typeof window != 'undefined';
2307+
var isWorker = typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
2308+
var isBrowser = typeof window != 'undefined' && !isWorker;
23072309
var Loader = global.Reflect && global.Reflect.Loader || require('./loader');
23082310
var Promise = global.Promise || require('when/es6-shim/Promise');
23092311

@@ -2350,7 +2352,7 @@ function logloads(loads) {
23502352
}
23512353

23522354
var fetchTextFromURL;
2353-
if (isBrowser) {
2355+
if (isBrowser || isWorker) {
23542356
fetchTextFromURL = function(url, fulfill, reject) {
23552357
var xhr = new XMLHttpRequest();
23562358
var sameDomain = true;
@@ -2403,7 +2405,7 @@ function logloads(loads) {
24032405
}
24042406

24052407
var System = new Loader({
2406-
global: isBrowser ? window : global,
2408+
global: isBrowser ? window : (isWorker ? self : global),
24072409
strict: true,
24082410
normalize: function(name, parentName, parentAddress) {
24092411
if (typeof name != 'string')
@@ -2491,14 +2493,12 @@ function logloads(loads) {
24912493
if (wildcard)
24922494
outPath = outPath.replace('*', wildcard);
24932495

2494-
// percent encode each path part
2495-
if (isBrowser) {
2496-
var outParts = outPath.split('/');
2497-
for (var i = 0, l = outParts.length; i < l; i++) {
2498-
outParts[i] = encodeURIComponent(outParts[i]);
2499-
}
2500-
outPath = outParts.join('/');
2501-
}
2496+
// percent encode just '#' in module names
2497+
// according to https://github.com/jorendorff/js-loaders/blob/master/browser-loader.js#L238
2498+
// we should encode everything, but it breaks for servers that don't expect it
2499+
// like in (https://github.com/systemjs/systemjs/issues/168)
2500+
if (isBrowser)
2501+
outPath = outPath.replace(/#/g, '%23');
25022502

25032503
return toAbsoluteURL(this.baseURL, outPath);
25042504
},
@@ -2512,8 +2512,8 @@ function logloads(loads) {
25122512
},
25132513
});
25142514

2515-
if (isBrowser) {
2516-
var href = window.location.href.split('#')[0].split('?')[0];
2515+
if (isBrowser || isWorker) {
2516+
var href = global.location.href.split('#')[0].split('?')[0];
25172517
System.baseURL = href.substring(0, href.lastIndexOf('/') + 1);
25182518
}
25192519
else {

dist/es6-module-loader.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/system.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@
205205
// according to https://github.com/jorendorff/js-loaders/blob/master/browser-loader.js#L238
206206
// we should encode everything, but it breaks for servers that don't expect it
207207
// like in (https://github.com/systemjs/systemjs/issues/168)
208-
if (isBrowser || isWorker)
209-
outPath = outPath.replace(/#/g, '%40');
208+
if (isBrowser)
209+
outPath = outPath.replace(/#/g, '%23');
210210

211211
return toAbsoluteURL(this.baseURL, outPath);
212212
},

0 commit comments

Comments
 (0)