From faa29945a3b73745a19ed7d3edd11ebf2717098e Mon Sep 17 00:00:00 2001 From: Vasu Bhog Date: Fri, 8 Oct 2021 15:24:00 -0700 Subject: [PATCH] Fix Link Callout Dialog consistency in split/md (#17313) * fix consistency with space and %20 files in split/md * add a test --- .../browser/calloutDialog/common/utils.ts | 16 +++++++++------- .../test/calloutDialog/linkCalloutDialog.test.ts | 3 +++ 2 files changed, 12 insertions(+), 7 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 6917ad449e..1885e9b76b 100644 --- a/src/sql/workbench/contrib/notebook/browser/calloutDialog/common/utils.ts +++ b/src/sql/workbench/contrib/notebook/browser/calloutDialog/common/utils.ts @@ -26,13 +26,15 @@ export function escapeLabel(unescapedLabel: string): string { */ export function escapeUrl(unescapedUrl: string): string { let firstEscape = strings.escape(unescapedUrl); - return firstEscape.replace(/[()]/g, function (match) { - switch (match) { - case '(': return '%28'; - case ')': return '%29'; - default: return match; - } - }); + return firstEscape.replace(/%20/g, '%2520') + .replace(/\s/g, '%20') + .replace(/[()]/g, function (match) { + switch (match) { + case '(': return '%28'; + case ')': return '%29'; + default: return match; + } + }); } /** 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 2e46f0856e..c4b19da77d 100644 --- a/src/sql/workbench/contrib/notebook/test/calloutDialog/linkCalloutDialog.test.ts +++ b/src/sql/workbench/contrib/notebook/test/calloutDialog/linkCalloutDialog.test.ts @@ -105,6 +105,9 @@ suite('Link Callout Dialog', function (): void { assert.strictEqual(escapeUrl('Test()URL'), 'Test%28%29URL', 'URL test square brackets failed'); assert.strictEqual(escapeUrl('<>&()'), '<>&%28%29', 'URL test known escaped characters failed'); assert.strictEqual(escapeUrl('<>&()[]'), '<>&%28%29[]', 'URL test all escaped characters failed'); + assert.strictEqual(escapeUrl('TEST URL'), 'TEST%20URL', 'URL with spaces failed'); + assert.strictEqual(escapeUrl('TEST%20URL'), 'TEST%2520URL', 'URL with %20 failed'); + assert.strictEqual(escapeUrl('TEST %20 URL'), 'TEST%20%2520%20URL', 'URL with %20 and spaces failed'); }); test('Unquote text', function (): void {