From cd49350239e90c84669db6f90cc50c5f75172ef3 Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Fri, 19 Aug 2016 12:07:14 -0700 Subject: [PATCH 1/2] Handle a baseURI of null When `ownerDocument.baseURI` is null (detached document, maybe some other cases), `new URL(url, baseURI)` will throw. Only use `new URL` when `baseURI` is not null. --- iron-image.html | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/iron-image.html b/iron-image.html index da3df07..9149464 100644 --- a/iron-image.html +++ b/iron-image.html @@ -396,8 +396,12 @@ }, _resolveSrc: function(testSrc) { - var baseURI = /** @type {string} */(this.ownerDocument.baseURI); - return (new URL(Polymer.ResolveUrl.resolveUrl(testSrc, baseURI), baseURI)).href; + var baseURI = this.ownerDocument.baseURI; + var resolvedUrl = Polymer.ResolveUrl.resolveUrl(testSrc, baseURI); + if (baseURI) { + resolvedUrl = new URL(resolvedUrl, baseURI).href; + } + return resolvedUrl; } }); From 897784ccc7be0cf803034b61a568538d96ba7710 Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Fri, 19 Aug 2016 14:48:55 -0700 Subject: [PATCH 2/2] Just use `new URL` On second thought, you really only need `new URL`. `Polymer.ResolveUrl.resolveUrl` is just doing the same thing as this. --- iron-image.html | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/iron-image.html b/iron-image.html index 9149464..64d2993 100644 --- a/iron-image.html +++ b/iron-image.html @@ -397,11 +397,10 @@ _resolveSrc: function(testSrc) { var baseURI = this.ownerDocument.baseURI; - var resolvedUrl = Polymer.ResolveUrl.resolveUrl(testSrc, baseURI); if (baseURI) { - resolvedUrl = new URL(resolvedUrl, baseURI).href; + return new URL(testSrc, baseURI).href; } - return resolvedUrl; + return testSrc; } });