Skip to content

Commit 733cf68

Browse files
authored
Run resolveUrl for protocol-relative urls (#5530)
* Run resolveUrl for protocol-relative urls This part of ABS_URL is trying to match on absolute paths, like `/images/logo.png` not protocol-relative urls like `//example.com/images/logo.png` Added a test and confirmed that it fails without this change. Also cleaned up a some over-aggressive modulizer escaping in resolveurl-elements.js Upstreaming cl/245302268
1 parent 03b2c66 commit 733cf68

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

lib/utils/resolve-url.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
1010
import './boot.js';
1111

1212
let CSS_URL_RX = /(url\()([^)]*)(\))/g;
13-
let ABS_URL = /(^\/)|(^#)|(^[\w-\d]*:)/;
13+
let ABS_URL = /(^\/[^\/])|(^#)|(^[\w-\d]*:)/;
1414
let workingURL;
1515
let resolveDoc;
1616
/**

test/unit/resolveurl.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@
154154
assert.equal(actual, expected);
155155
});
156156

157+
test('resolveUrl when called with a protocol-relative url', function () {
158+
const el = document.querySelector('x-resolve');
159+
const expected = `https://example.com/foo`;
160+
const actual =
161+
el.resolveUrl('//example.com/foo', 'https://example.org/bar');
162+
assert.equal(actual, expected);
163+
});
164+
157165
test('resolveUrl api with assetpath', function() {
158166
var el = document.createElement('p-r-ap');
159167
// Manually calculate expected URL, to avoid dependence on

test/unit/sub/resolveurl-elements.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ class PR extends PolymerElement {
3131
}
3232
</style>
3333
<div id="div" class="logo" style\$="background-image: url('[[importPath]]foo.z');"></div>
34-
<img id="img" src\$="[[importPath]]foo.z">
35-
<a id="a" href\$="[[importPath]]foo.z">Foo</a>
36-
<zonk id="import" url\$="[[importPath]]foo.z"></zonk>
37-
<zonk id="resolveUrl" url\$="[[resolveUrl('foo.z')]]"></zonk>
38-
<zonk id="resolveUrlHash" url\$="[[resolveUrl('#foo')]]"></zonk>
39-
<zonk id="resolveUrlAbs" url\$="[[resolveUrl('/foo')]]"></zonk>
40-
<zonk id="root" url\$="[[rootPath]]foo.z"></zonk>
41-
<a id="rel" href\$="[[importPath]]../foo.z?123">Foo</a>
34+
<img id="img" src$="[[importPath]]foo.z">
35+
<a id="a" href$="[[importPath]]foo.z">Foo</a>
36+
<zonk id="import" url$="[[importPath]]foo.z"></zonk>
37+
<zonk id="resolveUrl" url$="[[resolveUrl('foo.z')]]"></zonk>
38+
<zonk id="resolveUrlHash" url$="[[resolveUrl('#foo')]]"></zonk>
39+
<zonk id="resolveUrlAbs" url$="[[resolveUrl('/foo')]]"></zonk>
40+
<zonk id="root" url$="[[rootPath]]foo.z"></zonk>
41+
<a id="rel" href$="[[importPath]]../foo.z?123">Foo</a>
4242
<a id="action" action="foo.z">Foo</a>
43-
<form id="formAction" action\$="[[importPath]]foo.z"></form>
43+
<form id="formAction" action$="[[importPath]]foo.z"></form>
4444
<a id="hash" href="#foo.z">Foo</a>
4545
<a id="absolute" href="/foo.z">Foo</a>
4646
<a id="protocol" href="data:foo.z">Foo</a>

0 commit comments

Comments
 (0)