From db3a0ef7acefd58bb397d23cb930aba6f42bedfc Mon Sep 17 00:00:00 2001 From: Charles Gagnon Date: Tue, 15 Jun 2021 09:52:27 -0700 Subject: [PATCH] Trim pathname for link callout file paths (#15716) * Don't use pathname for link URLs * Trim pathname instead --- .../browser/cellViews/markdownToolbar.component.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/sql/workbench/contrib/notebook/browser/cellViews/markdownToolbar.component.ts b/src/sql/workbench/contrib/notebook/browser/cellViews/markdownToolbar.component.ts index 20c84fe968..be40097db6 100644 --- a/src/sql/workbench/contrib/notebook/browser/cellViews/markdownToolbar.component.ts +++ b/src/sql/workbench/contrib/notebook/browser/cellViews/markdownToolbar.component.ts @@ -351,10 +351,12 @@ export class MarkdownToolbarComponent extends AngularDisposable { private getCurrentLinkUrl(): string { if (this.cellModel.currentMode === CellEditModes.WYSIWYG) { - if (document.getSelection().anchorNode.parentNode['protocol'] === 'file:') { - return document.getSelection().anchorNode.parentNode['pathname'] || ''; + const parentNode = document.getSelection().anchorNode.parentNode as HTMLAnchorElement; + if (parentNode.protocol === 'file:') { + // Pathname starts with / per https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/pathname so trim it off + return parentNode.pathname?.slice(1) || ''; } else { - return document.getSelection().anchorNode.parentNode['href'] || ''; + return parentNode.href || ''; } } else { const editorControl = this.getCellEditorControl();