From 0bc8e54568f1d2f6df81e30fd07017ebb54acb9d Mon Sep 17 00:00:00 2001 From: Cory Rivera Date: Wed, 20 Oct 2021 18:12:39 -0700 Subject: [PATCH] Fix quoted link failures by removing quotes from unescaped paths, rather than just the escaped paths. (#17419) --- .../browser/calloutDialog/common/utils.ts | 2 +- .../calloutDialog/linkCalloutDialog.ts | 5 +++-- .../calloutDialog/linkCalloutDialog.test.ts | 22 +++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/sql/workbench/contrib/notebook/browser/calloutDialog/common/utils.ts b/src/sql/workbench/contrib/notebook/browser/calloutDialog/common/utils.ts index 1885e9b76b..38af416fcc 100644 --- a/src/sql/workbench/contrib/notebook/browser/calloutDialog/common/utils.ts +++ b/src/sql/workbench/contrib/notebook/browser/calloutDialog/common/utils.ts @@ -45,7 +45,7 @@ export function unquoteText(quotedText: string): string { let doubleQuotesRegex = /^[\"\'](.*)[\"\']$/; let matches = doubleQuotesRegex.exec(quotedText); if (matches && matches[1]) { - quotedText = matches[1]; + return matches[1]; } return quotedText; } diff --git a/src/sql/workbench/contrib/notebook/browser/calloutDialog/linkCalloutDialog.ts b/src/sql/workbench/contrib/notebook/browser/calloutDialog/linkCalloutDialog.ts index f5b7e2bdb3..4e596ee8cb 100644 --- a/src/sql/workbench/contrib/notebook/browser/calloutDialog/linkCalloutDialog.ts +++ b/src/sql/workbench/contrib/notebook/browser/calloutDialog/linkCalloutDialog.ts @@ -158,7 +158,8 @@ export class LinkCalloutDialog extends Modal { public insert(): void { this.hide('ok'); let escapedLabel = escapeLabel(this._linkTextInputBox.value); - let escapedUrl = escapeUrl(unquoteText(this._linkUrlInputBox.value)); + let unquotedUrl = unquoteText(this._linkUrlInputBox.value); + let escapedUrl = escapeUrl(unquotedUrl); if (this._previouslySelectedRange) { // Reset selection to previous state before callout was open @@ -169,7 +170,7 @@ export class LinkCalloutDialog extends Modal { this._selectionComplete.resolve({ insertEscapedMarkdown: `[${escapedLabel}](${escapedUrl})`, insertUnescapedLinkLabel: this._linkTextInputBox.value, - insertUnescapedLinkUrl: this._linkUrlInputBox.value + insertUnescapedLinkUrl: unquotedUrl }); } } diff --git a/src/sql/workbench/contrib/notebook/test/calloutDialog/linkCalloutDialog.test.ts b/src/sql/workbench/contrib/notebook/test/calloutDialog/linkCalloutDialog.test.ts index c4b19da77d..94b8e24a96 100644 --- a/src/sql/workbench/contrib/notebook/test/calloutDialog/linkCalloutDialog.test.ts +++ b/src/sql/workbench/contrib/notebook/test/calloutDialog/linkCalloutDialog.test.ts @@ -146,4 +146,26 @@ suite('Link Callout Dialog', function (): void { assert.strictEqual(result.insertEscapedMarkdown, `[${defaultLabel}](${sampleUrl})`, 'Markdown not returned correctly'); }); + test('Should handle quoted URLs properly', async function (): Promise { + const defaultLabel = 'defaultLabel'; + const unquotedUrl = 'C:/Test/Test.ipynb'; + const quotedUrl = `"${unquotedUrl}"`; + let linkCalloutDialog = new LinkCalloutDialog('Title', 'below', defaultDialogProperties, defaultLabel, '', + undefined, themeService, layoutService, telemetryService, contextKeyService, undefined, undefined, undefined); + linkCalloutDialog.render(); + + let deferred = new Deferred(); + // When I first open the callout dialog + linkCalloutDialog.open().then(value => { + deferred.resolve(value); + }); + linkCalloutDialog.url = quotedUrl; + + // And insert the dialog + linkCalloutDialog.insert(); + let result = await deferred.promise; + assert.strictEqual(result.insertUnescapedLinkLabel, defaultLabel, 'Label not returned correctly'); + assert.strictEqual(result.insertUnescapedLinkUrl, unquotedUrl, 'URL not unquoted correctly'); + assert.strictEqual(result.insertEscapedMarkdown, `[${defaultLabel}](${unquotedUrl})`, 'Markdown not unquoted correctly'); + }); });