Skip to content

Commit

Permalink
Use _importPath in resolveUrl so it available early. Fixes #4532
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Schaaf committed Apr 14, 2017
1 parent 3ce4e17 commit a08545c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/standard/resolveUrl.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @return {string} Rewritten URL relative to the import
*/
resolveUrl: function(url) {
return Polymer.ResolveUrl.resolveUrl(url, this.importPath);
return Polymer.ResolveUrl.resolveUrl(url, this._importPath);
}

});
Expand Down
16 changes: 16 additions & 0 deletions test/unit/resolveurl.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@
assert.equal(actual, expected);
});

test('resolveUrl used in property default', function() {
var el = document.createElement('p-r');
var expected = document.baseURI.replace(/[?#].*$/, '');
expected = expected.split('/');
expected.pop();
expected = expected.join('/') + '/sub/foo.png';
assert.equal(el.resolvedDefault, expected);
});

test('Hybrid: Urls in styles and attributes', function() {
var el = document.createElement('p-r-hybrid');
document.body.appendChild(el);
Expand All @@ -138,6 +147,13 @@
assert.equal(el.$.hash.getAttribute('href'), '#foo.z', 'hash-only url should not be resolved');
assert.equal(el.$.absolute.getAttribute('href'), '/foo.z', 'absolute urls should not be resolved');
assert.equal(el.$.protocol.getAttribute('href'), 'data:foo.z', 'urls with other protocols should not be resolved');
el.$.if.render();
assert.match(Polymer.dom(el.root).querySelector('#importIf')
.getAttribute('url'), rx, 'url url not relative to main document');
assert.match(Polymer.dom(el.root).querySelector('#resolveUrlIf')
.getAttribute('url'), rx, 'url url not relative to main document');
assert.notMatch(Polymer.dom(el.root).querySelector('#rootIf')
.getAttribute('url'), rx, 'url url not relative to main document');
document.body.removeChild(el);
});

Expand Down
16 changes: 15 additions & 1 deletion test/unit/sub/resolveurl-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@
</template>
</dom-module>
<script>
Polymer({is: 'p-r'});
Polymer({
is: 'p-r',
properties: {
resolvedDefault: {
value: function() {
return this.resolveUrl('foo.png');
}
}
}
});
</script>

<dom-module id="p-r-hybrid">
Expand All @@ -50,6 +59,11 @@
<a id="hash" href="#foo.z">Foo</a>
<a id="absolute" href="/foo.z">Foo</a>
<a id="protocol" href="data:foo.z">Foo</a>
<template is="dom-if" if id="if">
<zonk id="importIf" url$="[[importPath]]foo.z"></zonk>
<zonk id="resolveUrlIf" url$="[[resolveUrl('foo.z')]]"></zonk>
<zonk id="rootIf" url$="[[rootPath]]foo.z"></zonk>
</template>
</template>
</dom-module>
<script>
Expand Down

0 comments on commit a08545c

Please sign in to comment.