From 9c189ac94c4735e3a59ba1306fd78d2a59f388b5 Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Mon, 8 Jan 2018 16:53:33 +0100 Subject: [PATCH] Move absolute url logic to element-mixin This is backwards-compatible with the previous URL resolution. Now, `Polymer.ResolveUrl.resolveUrl` correctly appends the url to the basePath. --- lib/mixins/element-mixin.html | 5 +++++ lib/utils/resolve-url.html | 4 ---- test/unit/resolveurl.html | 6 ++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/mixins/element-mixin.html b/lib/mixins/element-mixin.html index 0a4c930145..2a4e50d35b 100644 --- a/lib/mixins/element-mixin.html +++ b/lib/mixins/element-mixin.html @@ -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, @@ -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); } diff --git a/lib/utils/resolve-url.html b/lib/utils/resolve-url.html index 357ef6a322..612847b1ce 100644 --- a/lib/utils/resolve-url.html +++ b/lib/utils/resolve-url.html @@ -15,7 +15,6 @@ 'use strict'; let CSS_URL_RX = /(url\()([^)]*)(\))/g; - let ABS_URL = /(^\/)|(^#)|(^[\w-\d]*:)/; let workingURL; let resolveDoc; /** @@ -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; diff --git a/test/unit/resolveurl.html b/test/unit/resolveurl.html index 8b08f692d3..ccf16ea873 100644 --- a/test/unit/resolveurl.html +++ b/test/unit/resolveurl.html @@ -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'); + }); + });