Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Fixes #68. Redirected url is no longer considered for de-duping, but …
Browse files Browse the repository at this point in the history
…redirected url is used as import baseURI.
  • Loading branch information
sorvell committed Aug 20, 2014
1 parent 33676ab commit 1babe09
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/HTMLImports.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ if (!useNative) {
return doc === mainDoc ? this.documentPreloadSelectors :
this.importsPreloadSelectors;
},
loaded: function(url, elt, resource, err) {
loaded: function(url, elt, resource, err, redirectedUrl) {
flags.load && console.log('loaded', url, elt);
// store generic resource
// TODO(sorvell): fails for nodes inside <template>.content
Expand All @@ -68,7 +68,7 @@ if (!useNative) {
// if we've never seen a document at this url
if (doc === undefined) {
// generate an HTMLDocument from data
doc = err ? null : makeDocument(resource, url);
doc = err ? null : makeDocument(resource, redirectedUrl || url);
if (doc) {
doc.__importLink = elt;
// note, we cannot use MO to detect parsed nodes because
Expand Down
17 changes: 4 additions & 13 deletions src/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,13 @@
receive: function(url, elt, err, resource, redirectedUrl) {
this.cache[url] = resource;
var $p = this.pending[url];
if ( redirectedUrl && redirectedUrl !== url ) {
this.cache[redirectedUrl] = resource;
$p = $p.concat(this.pending[redirectedUrl]);
}
for (var i=0, l=$p.length, p; (i<l) && (p=$p[i]); i++) {
//if (!err) {
// If url was redirected, use the redirected location so paths are
// calculated relative to that.
this.onload(redirectedUrl || url, p, resource, err);
//}
// If url was redirected, use the redirected location so paths are
// calculated relative to that.
this.onload(url, p, resource, err, redirectedUrl);
this.tail();
}
this.pending[url] = null;
if ( redirectedUrl && redirectedUrl !== url ) {
this.pending[redirectedUrl] = null;
}
},
tail: function() {
--this.inflight;
Expand Down Expand Up @@ -164,7 +155,7 @@
if (locationHeader) {
var redirectedUrl = (locationHeader.substr( 0, 1 ) === "/")
? location.origin + locationHeader // Location is a relative path
: redirectedUrl; // Full path
: locationHeader; // Full path
}
next.call(nextContext, !xhr.ok(request) && request,
request.response || request.responseText, redirectedUrl);
Expand Down
3 changes: 3 additions & 0 deletions test/html/redirect/imports/load.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script>
load = true;
</script>
Binary file added test/html/redirect/imports/redirect/googley.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions test/html/redirect/imports/redirect/load.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script>
redirect = true;
</script>
<style>
.image {
background: url(googley.png);
height: 190px;
width: 538px;
}
</style>
27 changes: 27 additions & 0 deletions test/html/redirect/load-redirect.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!doctype html>
<html>
<head>
<title>load redirect Test</title>
<script src="../../../../tools/test/htmltest.js"></script>
<script src="../../../../tools/test/chai/chai.js"></script>
<script src="../../../html-imports.js"></script>
<link rel="import" href="imports/load-1.html">
</head>
<body>
<div id="test" class="image"></div>
<script>
document.addEventListener('HTMLImportsLoaded', function() {
chai.assert.ok(window.redirect, 'redirected script ran');
var l = document.querySelector('link');
var a = document.createElement('a');
a.href = 'imports/redirect/load.html';
chai.assert.match(l.import.baseURI, new RegExp(a.pathname), 'import baseURI redirected');
setTimeout(function() {
var bg = getComputedStyle(document.querySelector('#test')).backgroundImage;
chai.assert.match(bg, /redirect\/googley.png/, 'import image properly referenced');
done();
});
});
</script>
</body>
</html>

0 comments on commit 1babe09

Please sign in to comment.