From 733cf6831cc3ea1f55ae947d283055b9b77d8817 Mon Sep 17 00:00:00 2001 From: Peter Burns Date: Thu, 25 Apr 2019 17:41:14 -0700 Subject: [PATCH] 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 --- lib/utils/resolve-url.js | 2 +- test/unit/resolveurl.html | 8 ++++++++ test/unit/sub/resolveurl-elements.js | 18 +++++++++--------- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/utils/resolve-url.js b/lib/utils/resolve-url.js index 06b2292e12..96bb61004c 100644 --- a/lib/utils/resolve-url.js +++ b/lib/utils/resolve-url.js @@ -10,7 +10,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN import './boot.js'; let CSS_URL_RX = /(url\()([^)]*)(\))/g; -let ABS_URL = /(^\/)|(^#)|(^[\w-\d]*:)/; +let ABS_URL = /(^\/[^\/])|(^#)|(^[\w-\d]*:)/; let workingURL; let resolveDoc; /** diff --git a/test/unit/resolveurl.html b/test/unit/resolveurl.html index 7a3106beca..0d9a193a78 100644 --- a/test/unit/resolveurl.html +++ b/test/unit/resolveurl.html @@ -154,6 +154,14 @@ assert.equal(actual, expected); }); + test('resolveUrl when called with a protocol-relative url', function () { + const el = document.querySelector('x-resolve'); + const expected = `https://example.com/foo`; + const actual = + el.resolveUrl('//example.com/foo', 'https://example.org/bar'); + assert.equal(actual, expected); + }); + test('resolveUrl api with assetpath', function() { var el = document.createElement('p-r-ap'); // Manually calculate expected URL, to avoid dependence on diff --git a/test/unit/sub/resolveurl-elements.js b/test/unit/sub/resolveurl-elements.js index 59ba24447e..3fc0faba8b 100644 --- a/test/unit/sub/resolveurl-elements.js +++ b/test/unit/sub/resolveurl-elements.js @@ -31,16 +31,16 @@ class PR extends PolymerElement { } - - Foo - - - - - - Foo + + Foo + + + + + + Foo Foo -
+
Foo Foo Foo