Skip to content

Commit

Permalink
Merge pull request Polymer#84 from Polymer/hash
Browse files Browse the repository at this point in the history
Fixes polymer Polymer#672
  • Loading branch information
dfreedm committed Oct 8, 2014
2 parents a23ea1e + efcb1a1 commit fc3b80a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ var CSS_IMPORT_REGEXP = /(@import[\s]+(?!url\())([^;]*)(;)/g;
var URL_ATTRS = ['href', 'src', 'action', 'style', 'url'];
var URL_ATTRS_SELECTOR = '[' + URL_ATTRS.join('],[') + ']';
var URL_TEMPLATE_SEARCH = '{{.*}}';
var URL_HASH = '#';

function replaceUrlsInCssText(cssText, baseUrl, keepAbsolute, regexp) {
return cssText.replace(regexp, function(m, pre, url, post) {
Expand Down Expand Up @@ -120,7 +121,9 @@ function makeRelPath(sourceUrl, targetUrl) {
for (var i = 0, l = s.length - 1; i < l; i++) {
t.unshift('..');
}
return t.join('/') + targetUrl.search + targetUrl.hash;
// empty '#' is discarded but we need to preserve it.
var hash = (targetUrl.href.slice(-1) === URL_HASH) ? URL_HASH : targetUrl.hash;
return t.join('/') + targetUrl.search + hash;
}

// exports
Expand Down
2 changes: 2 additions & 0 deletions test/html/url.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<b id="a" href="/1/2"></b>
<b id="b" href="2/../3/4"></b>
<b id="c" href="{{ path }}/baz"></b>
<b id="d" href="#"></b>
</template>
<script>
addEventListener('HTMLImportsLoaded', function() {
Expand All @@ -32,6 +33,7 @@
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');
chai.assert.equal(getUrl(t, 'd', 'href'), '#');
done();
});
</script>
Expand Down

0 comments on commit fc3b80a

Please sign in to comment.