DataLinks: Ensure window origin to be stripped from url when using absolute urls (#32634)

* Ensure window origin to be stripped from url when using absolute urls

* Update test

* Make sure link interception works for external links

* Apply suggestions from code review

* Review
This commit is contained in:
Dominik Prokop
2021-04-08 17:38:56 +02:00
committed by GitHub
parent d6c824fe18
commit deccc97985
3 changed files with 73 additions and 11 deletions

View File

@ -19,11 +19,20 @@ export function interceptLinkClicks(e: MouseEvent) {
href = locationUtil.stripBaseFromUrl(href);
// Ensure old angular urls with no starting '/' are handled the same as before
// Make sure external links are handled correctly
// That is they where seen as being absolute from app root
if (href[0] !== '/') {
try {
const external = new URL(href);
if (external.origin !== window.location.origin) {
window.location.href = external.toString();
return;
}
} catch (e) {
console.warn(e);
}
href = `/${href}`;
}
locationService.push(href);
}
}