Skip to content

Commit

Permalink
Fixes #1508, make sure blob URLs work even with urlArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
jrburke committed Mar 15, 2016
1 parent 39e682b commit d83e6d4
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
6 changes: 3 additions & 3 deletions require.js
Expand Up @@ -1675,12 +1675,12 @@ var requirejs, require, define;

//Join the path parts together, then figure out if baseUrl is needed.
url = syms.join('/');
url += (ext || (/^data\:|\?/.test(url) || skipExt ? '' : '.js'));
url += (ext || (/^data\:|^blob\:|\?/.test(url) || skipExt ? '' : '.js'));
url = (url.charAt(0) === '/' || url.match(/^[\w\+\.\-]+:/) ? '' : config.baseUrl) + url;
}

return config.urlArgs ? url + config.urlArgs(moduleName, url) :
url;
return config.urlArgs && !/^blob\:/.test(url) ?
url + config.urlArgs(moduleName, url) : url;
},

//Delegates to req.load. Broken out as a separate function to
Expand Down
4 changes: 4 additions & 0 deletions tests/all.js
Expand Up @@ -14,6 +14,10 @@ doh.registerUrl("toUrl", "../toUrl/toUrl.html");
doh.registerUrl("urlArgsToUrl", "../urlArgsToUrl.html");
doh.registerUrl("urlArgsToUrlFunction", "../urlArgsToUrlFunction.html");

if (typeof Blob === 'function') {
doh.registerUrl("urlArgsBlob", "../urlArgsBlob.html");
}

doh.registerUrl("config", "../config.html");
doh.registerUrl("configRequirejs", "../configRequirejs.html");
doh.registerUrl("dataMain", "../dataMain/dataMain.html");
Expand Down
45 changes: 45 additions & 0 deletions tests/urlArgsBlob.html
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html>
<head>
<title>require.js: urlArgsBlob Test</title>
<script type="text/javascript" src="doh/runner.js"></script>
<script type="text/javascript" src="doh/_browserRunner.js"></script>
<script type="text/javascript" src="../require.js"></script>
<script>

var blob = new Blob(["define({name: 'a'});"],
{type : 'application/javascript'});

var url = URL.createObjectURL(blob);

console.log(url);

require.config({
baseUrl: 'js',
urlArgs: 'v=1234',
paths: {
a: url
}
});

require(['a'], function(a) {
doh.register(
'urlArgsBlob',
[
function urlArgsBlob(t){
t.is(url, require.toUrl('a'));
t.is('a', a.name);
}
]
);
doh.run();
});
</script>
</head>
<body>
<h1>require.js: urlArgsBlob Test</h1>
<p>Makes sure urlArgs are not applied to blob URLs.
<a href="https://github.com/requirejs/requirejs/issues/1508">More info</a>.
<p>Check console for messages.</p>
</body>
</html>

0 comments on commit d83e6d4

Please sign in to comment.