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
This commit is contained in:
Viktar Donich
2018-05-07 15:56:35 -07:00
parent 003968da85
commit 9715d7f596
2 changed files with 2 additions and 3 deletions

View File

@@ -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;
},
});
})();

View File

@@ -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(() => {