Skip to content

Commit

Permalink
Move absolute url logic to element-mixin
Browse files Browse the repository at this point in the history
This is backwards-compatible with the previous URL resolution.
Now, `Polymer.ResolveUrl.resolveUrl` correctly appends the url
to the basePath.
  • Loading branch information
TimvdLippe committed Jan 8, 2018
1 parent e40c8d9 commit 9c189ac
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lib/mixins/element-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
(function() {
'use strict';

const ABS_URL = /(^\/)|(^#)|(^[\w-\d]*:)/;

/**
* Element class mixin that provides the core API for Polymer's meta-programming
* features including template stamping, data-binding, attribute deserialization,
Expand Down Expand Up @@ -636,6 +638,9 @@
* @return {string} Rewritten URL relative to base
*/
resolveUrl(url, base) {
if (url && ABS_URL.test(url)) {
return url;
}
if (!base && this.importPath) {
base = Polymer.ResolveUrl.resolveUrl(this.importPath);
}
Expand Down
4 changes: 0 additions & 4 deletions lib/utils/resolve-url.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
'use strict';

let CSS_URL_RX = /(url\()([^)]*)(\))/g;
let ABS_URL = /(^\/)|(^#)|(^[\w-\d]*:)/;
let workingURL;
let resolveDoc;
/**
Expand All @@ -27,9 +26,6 @@
* @return {string} resolved URL
*/
function resolveUrl(url, baseURI) {
if (url && ABS_URL.test(url)) {
return url;
}
// Lazy feature detection.
if (workingURL === undefined) {
workingURL = false;
Expand Down
6 changes: 6 additions & 0 deletions test/unit/resolveurl.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@
assert.equal(actual, expected);
});
});

suite('Polymer.ResolveUrl', function() {
test('appends absolute url to basePath', function() {
assert.equal(Polymer.ResolveUrl.resolveUrl('/foo', 'http://localhost'), 'http://localhost/foo');
});
});
</script>
</body>
</html>

0 comments on commit 9c189ac

Please sign in to comment.