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

Commit 701d348

Browse files
committed
Make paths relative only if they start the same.
1 parent 830760c commit 701d348

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

src/HTMLImports.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ var path = {
288288
return url;
289289
}
290290
url = this.compressUrl(this.urlToPath(baseUrl) + url);
291-
if (relativeToDocument && !this.isAbsUrl(url)) {
291+
if (relativeToDocument) {
292292
url = path.makeRelPath(path.getDocumentUrl(document), url);
293293
}
294294
return url;
@@ -325,6 +325,10 @@ var path = {
325325
var s, t;
326326
s = this.compressUrl(inSource).split("/");
327327
t = this.compressUrl(inTarget).split("/");
328+
// bail if target is not relative to source
329+
if (!s.length || s[0] !== t[0]) {
330+
return inTarget;
331+
}
328332
while (s.length && s[0] === t[0]){
329333
s.shift();
330334
t.shift();

test/html/imports/abs.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<img src="../../foo.png">

test/html/path.html

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
<script src="../../tools/test/htmltest.js"></script>
77
<script src="../../node_modules/chai/chai.js"></script>
88
<script src="../../html-imports.js"></script>
9+
<script>
10+
var parts = window.location.pathname.split('/');
11+
parts.pop();
12+
var absBase = parts.join('/');
13+
var l = document.createElement('link');
14+
l.setAttribute('rel', 'import');
15+
l.href = absBase + '/imports/abs.html';
16+
document.head.appendChild(l);
17+
</script>
918
</head>
1019
<body>
1120
<script>
@@ -16,7 +25,18 @@
1625
url = 'http://foo/bar?baz="foo/../bar"';
1726
chai.assert.equal(path.compressUrl(url), url, 'query string is not counted in path compression');
1827

19-
done();
28+
url = '/foo/bar/baz"';
29+
chai.assert.equal(path.compressUrl(url), url, 'compressUrl handles url\'s starting with / as abs');
30+
document.addEventListener('HTMLImportsLoaded', function() {
31+
var i = document.querySelector('[rel=import]');
32+
var importDoc = i.import.content;
33+
var parts = window.location.href.split('/');
34+
parts.pop();
35+
parts.pop();
36+
var expectedPath = parts.join('/') + '/foo.png';
37+
chai.assert.equal(importDoc.querySelector('img').src, expectedPath);
38+
done();
39+
});
2040
</script>
2141
</body>
2242
</html>

0 commit comments

Comments
 (0)