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

Commit

Permalink
Do not rewrite '/' absolute urls
Browse files Browse the repository at this point in the history
Make URL test actually test the url resolver

Fixes Polymer/platform#63
  • Loading branch information
dfreedm committed Apr 19, 2014
1 parent c90023a commit 55131c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ function replaceUrlsInCssText(cssText, baseUrl, regexp) {
}

function resolveRelativeUrl(baseUrl, url) {
// do not resolve '/' absolute urls
if (url && url[0] === '/') {
return url;
}
var u = new URL(url, baseUrl);
return makeDocumentRelPath(u.href);
}
Expand Down
20 changes: 13 additions & 7 deletions test/html/url.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@
<script src="../../platform.js"></script>
</head>
<body>
<template>
<b id="a" href="/1/2"></b>
<b id="b" href="2/../3/4"></b>
<b id="c" href="{{ path }}/baz"></b>
</template>
<script>
var root = document.location;
var path = '/foo/bar';
var u = new URL(path, root);
chai.assert.equal(u.host, root.host);
chai.assert.equal(u.port, root.port);
chai.assert.equal(u.protocol, root.protocol);
chai.assert.equal(u.pathname, path);
function getUrl(template, id, attr) {
return template.content.querySelector('#' + id).getAttribute(attr);
}
var t = document.querySelector('template');
Platform.urlResolver.resolveTemplate(t);
chai.assert.equal(getUrl(t, 'a', 'href'), '/1/2');
chai.assert.equal(getUrl(t, 'b', 'href'), '3/4');
chai.assert.equal(getUrl(t, 'c', 'href'), '{{ path }}/baz');
done();
</script>
</body>
Expand Down

0 comments on commit 55131c2

Please sign in to comment.