@@ -35,15 +35,18 @@ var sourcemint = null;
35
35
36
36
// @credit https://github.com/unscriptable/curl/blob/62caf808a8fd358ec782693399670be6806f1845/src/curl.js#L319-360
37
37
function loadInBrowser ( uri , loadedCallback ) {
38
- if ( / ^ \/ / . test ( uri ) ) {
39
- uri = document . location . protocol + "/" + uri ;
40
- }
41
38
// See if we are in a web worker.
42
39
if ( typeof importScripts !== "undefined" ) {
43
- importScripts ( uri ) ;
40
+ importScripts ( uri . replace ( / ^ \{ h o s t \} / , "" ) ) ;
44
41
loadedCallback ( ) ;
45
42
return ;
46
43
}
44
+ if ( / ^ \{ h o s t \} \/ / . test ( uri ) ) {
45
+ uri = document . location . protocol + "//" + document . location . host + uri . substring ( 6 ) ;
46
+ } else
47
+ if ( / ^ \/ / . test ( uri ) ) {
48
+ uri = document . location . protocol + "/" + uri ;
49
+ }
47
50
if ( ! headTag ) {
48
51
headTag = document . getElementsByTagName ( "head" ) [ 0 ] ;
49
52
}
@@ -208,6 +211,13 @@ var sourcemint = null;
208
211
{
209
212
arguments [ 2 ] . load = arguments [ 2 ] . load || sandboxOptions . load ;
210
213
}
214
+ // If the `programIdentifier` (first argument) is relative it is resolved against the URI of the owning sandbox (not the owning page).
215
+ if ( / ^ \. / . test ( arguments [ 0 ] ) )
216
+ {
217
+ arguments [ 0 ] = sandboxIdentifier . replace ( / \/ [ ^ \/ ] * $ / , "" ) + "/" + arguments [ 0 ] ;
218
+ // HACK: Temporary hack as zombie (https://github.com/assaf/zombie) does not normalize path before sending to server.
219
+ arguments [ 0 ] = arguments [ 0 ] . replace ( / \/ \. \/ / g, "/" ) ;
220
+ }
211
221
return sourcemint . sandbox . apply ( null , arguments ) ;
212
222
}
213
223
module . require . sandbox . id = sandboxIdentifier ;
@@ -392,6 +402,7 @@ var sourcemint = null;
392
402
] ;
393
403
394
404
// Create a new environment to memoize modules to.
405
+ // If relative, the `programIdentifier` is resolved against the URI of the owning page (this is only for the global require).
395
406
require . sandbox = function ( programIdentifier , loadedCallback , options ) {
396
407
var sandboxIdentifier = programIdentifier . replace ( / \. j s $ / , "" ) ;
397
408
return sandboxes [ sandboxIdentifier ] = Sandbox ( sandboxIdentifier , loadedCallback , options || { } ) ;
0 commit comments