From 9715d7f5965e0e0f761ebf2bc04b10a31e89c00b Mon Sep 17 00:00:00 2001 From: Viktar Donich Date: Mon, 7 May 2018 15:56:35 -0700 Subject: [PATCH] Use URL.origin instead of URL.pathname If the app gets initialized before being redirected from empty URL (e.g. https://gerrit-review.googlesource.com/), the trailing slash is returned as pathname resutlting in _getUrl() returning 'https:' thus generating valid URL for loading plugins. This masked the actual problem by generating valid plugin URLs while waiting for loading from the invalid ones. Use URL.origin() instead for building full plugin URLs. Bug: Issue 8941 Change-Id: I65bad6c4b1c418c2588e131073b2d4ba8b80117c --- .../app/elements/plugins/gr-plugin-host/gr-plugin-host.js | 3 +-- .../elements/plugins/gr-plugin-host/gr-plugin-host_test.html | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/polygerrit-ui/app/elements/plugins/gr-plugin-host/gr-plugin-host.js b/polygerrit-ui/app/elements/plugins/gr-plugin-host/gr-plugin-host.js index a7cfca365c..c5bf21a530 100644 --- a/polygerrit-ui/app/elements/plugins/gr-plugin-host/gr-plugin-host.js +++ b/polygerrit-ui/app/elements/plugins/gr-plugin-host/gr-plugin-host.js @@ -102,8 +102,7 @@ if (!pathOrUrl.startsWith('/')) { pathOrUrl = '/' + pathOrUrl; } - const {href, pathname} = window.location; - return href.split(pathname)[0] + this.getBaseUrl() + pathOrUrl; + return window.location.origin + this.getBaseUrl() + pathOrUrl; }, }); })(); diff --git a/polygerrit-ui/app/elements/plugins/gr-plugin-host/gr-plugin-host_test.html b/polygerrit-ui/app/elements/plugins/gr-plugin-host/gr-plugin-host_test.html index daa86fad73..0880d73549 100644 --- a/polygerrit-ui/app/elements/plugins/gr-plugin-host/gr-plugin-host_test.html +++ b/polygerrit-ui/app/elements/plugins/gr-plugin-host/gr-plugin-host_test.html @@ -43,7 +43,7 @@ limitations under the License. sandbox = sinon.sandbox.create(); sandbox.stub(document.body, 'appendChild'); sandbox.stub(element, 'importHref'); - url = window.location.href.split(window.location.pathname)[0]; + url = window.location.origin; }); teardown(() => {