From 516ece3c0c79f2441023cf75443547314f144ad6 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Fri, 15 Dec 2017 11:31:09 +0100 Subject: [PATCH] fix: external links with hash are updated incorrectly External links with a hash are incorrectly updated, because they are considered as hash links that are referring to a local anchor on the current page (fragment links). --- src/app/shared/doc-viewer/doc-viewer.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app/shared/doc-viewer/doc-viewer.ts b/src/app/shared/doc-viewer/doc-viewer.ts index 6dfad6d62..a415f5fe5 100644 --- a/src/app/shared/doc-viewer/doc-viewer.ts +++ b/src/app/shared/doc-viewer/doc-viewer.ts @@ -115,8 +115,10 @@ export class DocViewer implements OnDestroy { const anchorElements = [].slice.call(this._elementRef.nativeElement.querySelectorAll('a')) as HTMLAnchorElement[]; + // Update hash links that are referring to the same page and host. Links that are referring + // to a different destination shouldn't be updated. For example the Google Fonts URL. anchorElements - .filter(anchorEl => anchorEl.hash) + .filter(anchorEl => anchorEl.hash && anchorEl.host === location.host) .forEach(anchorEl => anchorEl.href = `${baseUrl}${anchorEl.hash}`); }