mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Remove quotes from inserted markdown links (#16457)
This commit is contained in:
@@ -34,3 +34,16 @@ export function escapeUrl(unescapedUrl: string): string {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes single or double quotes that enclose another string.
|
||||||
|
* @param quotedText The text to unquote
|
||||||
|
*/
|
||||||
|
export function unquoteText(quotedText: string): string {
|
||||||
|
let doubleQuotesRegex = /^[\"\'](.*)[\"\']$/;
|
||||||
|
let matches = doubleQuotesRegex.exec(quotedText);
|
||||||
|
if (matches && matches[1]) {
|
||||||
|
quotedText = matches[1];
|
||||||
|
}
|
||||||
|
return quotedText;
|
||||||
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import { Checkbox } from 'sql/base/browser/ui/checkbox/checkbox';
|
|||||||
import { RadioButton } from 'sql/base/browser/ui/radioButton/radioButton';
|
import { RadioButton } from 'sql/base/browser/ui/radioButton/radioButton';
|
||||||
import { attachCalloutDialogStyler } from 'sql/workbench/common/styler';
|
import { attachCalloutDialogStyler } from 'sql/workbench/common/styler';
|
||||||
import * as path from 'vs/base/common/path';
|
import * as path from 'vs/base/common/path';
|
||||||
|
import { unquoteText } from 'sql/workbench/contrib/notebook/browser/calloutDialog/common/utils';
|
||||||
|
|
||||||
export interface IImageCalloutDialogOptions {
|
export interface IImageCalloutDialogOptions {
|
||||||
insertTitle?: string,
|
insertTitle?: string,
|
||||||
@@ -199,7 +200,7 @@ export class ImageCalloutDialog extends Modal {
|
|||||||
|
|
||||||
public insert(): void {
|
public insert(): void {
|
||||||
this.hide('ok');
|
this.hide('ok');
|
||||||
let imgPath = this._imageUrlInputBox.value;
|
let imgPath = unquoteText(this._imageUrlInputBox.value);
|
||||||
let imageName = path.basename(imgPath);
|
let imageName = path.basename(imgPath);
|
||||||
this._selectionComplete.resolve({
|
this._selectionComplete.resolve({
|
||||||
embedImage: this._imageEmbedCheckbox.checked,
|
embedImage: this._imageEmbedCheckbox.checked,
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import { Deferred } from 'sql/base/common/promise';
|
|||||||
import { InputBox } from 'sql/base/browser/ui/inputBox/inputBox';
|
import { InputBox } from 'sql/base/browser/ui/inputBox/inputBox';
|
||||||
import { attachCalloutDialogStyler } from 'sql/workbench/common/styler';
|
import { attachCalloutDialogStyler } from 'sql/workbench/common/styler';
|
||||||
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
|
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
|
||||||
import { escapeLabel, escapeUrl } from 'sql/workbench/contrib/notebook/browser/calloutDialog/common/utils';
|
import { escapeLabel, escapeUrl, unquoteText } from 'sql/workbench/contrib/notebook/browser/calloutDialog/common/utils';
|
||||||
|
|
||||||
export interface ILinkCalloutDialogOptions {
|
export interface ILinkCalloutDialogOptions {
|
||||||
insertTitle?: string,
|
insertTitle?: string,
|
||||||
@@ -158,7 +158,7 @@ export class LinkCalloutDialog extends Modal {
|
|||||||
public insert(): void {
|
public insert(): void {
|
||||||
this.hide('ok');
|
this.hide('ok');
|
||||||
let escapedLabel = escapeLabel(this._linkTextInputBox.value);
|
let escapedLabel = escapeLabel(this._linkTextInputBox.value);
|
||||||
let escapedUrl = escapeUrl(this._linkUrlInputBox.value);
|
let escapedUrl = escapeUrl(unquoteText(this._linkUrlInputBox.value));
|
||||||
|
|
||||||
if (this._previouslySelectedRange) {
|
if (this._previouslySelectedRange) {
|
||||||
// Reset selection to previous state before callout was open
|
// Reset selection to previous state before callout was open
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { IAdsTelemetryService } from 'sql/platform/telemetry/common/telemetry';
|
|||||||
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
||||||
import { MockContextKeyService } from 'vs/platform/keybinding/test/common/mockKeybindingService';
|
import { MockContextKeyService } from 'vs/platform/keybinding/test/common/mockKeybindingService';
|
||||||
import { Deferred } from 'sql/base/common/promise';
|
import { Deferred } from 'sql/base/common/promise';
|
||||||
import { escapeLabel, escapeUrl } from 'sql/workbench/contrib/notebook/browser/calloutDialog/common/utils';
|
import { escapeLabel, escapeUrl, unquoteText } from 'sql/workbench/contrib/notebook/browser/calloutDialog/common/utils';
|
||||||
import { IDialogProperties } from 'sql/workbench/browser/modal/modal';
|
import { IDialogProperties } from 'sql/workbench/browser/modal/modal';
|
||||||
|
|
||||||
suite('Link Callout Dialog', function (): void {
|
suite('Link Callout Dialog', function (): void {
|
||||||
@@ -42,9 +42,9 @@ suite('Link Callout Dialog', function (): void {
|
|||||||
linkCalloutDialog.cancel();
|
linkCalloutDialog.cancel();
|
||||||
let result = await deferred.promise;
|
let result = await deferred.promise;
|
||||||
|
|
||||||
assert.equal(result.insertUnescapedLinkLabel, 'defaultLabel', 'Label not returned correctly');
|
assert.strictEqual(result.insertUnescapedLinkLabel, 'defaultLabel', 'Label not returned correctly');
|
||||||
assert.equal(result.insertUnescapedLinkUrl, undefined, 'URL not returned correctly');
|
assert.strictEqual(result.insertUnescapedLinkUrl, undefined, 'URL not returned correctly');
|
||||||
assert.equal(result.insertEscapedMarkdown, '', 'Markdown not returned correctly');
|
assert.strictEqual(result.insertEscapedMarkdown, '', 'Markdown not returned correctly');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Should return expected values on insert', async function (): Promise<void> {
|
test('Should return expected values on insert', async function (): Promise<void> {
|
||||||
@@ -65,9 +65,9 @@ suite('Link Callout Dialog', function (): void {
|
|||||||
// And insert the dialog
|
// And insert the dialog
|
||||||
linkCalloutDialog.insert();
|
linkCalloutDialog.insert();
|
||||||
let result = await deferred.promise;
|
let result = await deferred.promise;
|
||||||
assert.equal(result.insertUnescapedLinkLabel, defaultLabel, 'Label not returned correctly');
|
assert.strictEqual(result.insertUnescapedLinkLabel, defaultLabel, 'Label not returned correctly');
|
||||||
assert.equal(result.insertUnescapedLinkUrl, sampleUrl, 'URL not returned correctly');
|
assert.strictEqual(result.insertUnescapedLinkUrl, sampleUrl, 'URL not returned correctly');
|
||||||
assert.equal(result.insertEscapedMarkdown, `[${defaultLabel}](${sampleUrl})`, 'Markdown not returned correctly');
|
assert.strictEqual(result.insertEscapedMarkdown, `[${defaultLabel}](${sampleUrl})`, 'Markdown not returned correctly');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Should return expected values on insert when escape necessary', async function (): Promise<void> {
|
test('Should return expected values on insert when escape necessary', async function (): Promise<void> {
|
||||||
@@ -88,23 +88,37 @@ suite('Link Callout Dialog', function (): void {
|
|||||||
// And insert the dialog
|
// And insert the dialog
|
||||||
linkCalloutDialog.insert();
|
linkCalloutDialog.insert();
|
||||||
let result = await deferred.promise;
|
let result = await deferred.promise;
|
||||||
assert.equal(result.insertUnescapedLinkLabel, defaultLabel, 'Label not returned correctly');
|
assert.strictEqual(result.insertUnescapedLinkLabel, defaultLabel, 'Label not returned correctly');
|
||||||
assert.equal(result.insertUnescapedLinkUrl, sampleUrl, 'URL not returned correctly');
|
assert.strictEqual(result.insertUnescapedLinkUrl, sampleUrl, 'URL not returned correctly');
|
||||||
assert.equal(result.insertEscapedMarkdown, '[default\[\]Label](https://www.aka.ms/azuredatastudio%28%29)', 'Markdown not returned correctly');
|
assert.strictEqual(result.insertEscapedMarkdown, '[default\[\]Label](https://www.aka.ms/azuredatastudio%28%29)', 'Markdown not returned correctly');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Label escape', function (): void {
|
test('Label escape', function (): void {
|
||||||
assert.equal(escapeLabel('TestLabel'), 'TestLabel', 'Basic escape label test failed');
|
assert.strictEqual(escapeLabel('TestLabel'), 'TestLabel', 'Basic escape label test failed');
|
||||||
assert.equal(escapeLabel('Test[]Label'), 'Test\[\]Label', 'Label test square brackets failed');
|
assert.strictEqual(escapeLabel('Test[]Label'), 'Test\[\]Label', 'Label test square brackets failed');
|
||||||
assert.equal(escapeLabel('<>&[]'), '<>&\[\]', 'Label test known escaped characters failed');
|
assert.strictEqual(escapeLabel('<>&[]'), '<>&\[\]', 'Label test known escaped characters failed');
|
||||||
assert.equal(escapeLabel('<>&[]()'), '<>&\[\]()', 'Label test all escaped characters failed');
|
assert.strictEqual(escapeLabel('<>&[]()'), '<>&\[\]()', 'Label test all escaped characters failed');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('URL escape', function (): void {
|
test('URL escape', function (): void {
|
||||||
assert.equal(escapeUrl('TestURL'), 'TestURL', 'Basic escape URL test failed');
|
assert.strictEqual(escapeUrl('TestURL'), 'TestURL', 'Basic escape URL test failed');
|
||||||
assert.equal(escapeUrl('Test()URL'), 'Test%28%29URL', 'URL test square brackets failed');
|
assert.strictEqual(escapeUrl('Test()URL'), 'Test%28%29URL', 'URL test square brackets failed');
|
||||||
assert.equal(escapeUrl('<>&()'), '<>&%28%29', 'URL test known escaped characters failed');
|
assert.strictEqual(escapeUrl('<>&()'), '<>&%28%29', 'URL test known escaped characters failed');
|
||||||
assert.equal(escapeUrl('<>&()[]'), '<>&%28%29[]', 'URL test all escaped characters failed');
|
assert.strictEqual(escapeUrl('<>&()[]'), '<>&%28%29[]', 'URL test all escaped characters failed');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Unquote text', function (): void {
|
||||||
|
assert.strictEqual(unquoteText('TestPath'), 'TestPath');
|
||||||
|
assert.strictEqual(unquoteText('\"TestPath\"'), 'TestPath');
|
||||||
|
assert.strictEqual(unquoteText('\'TestPath\''), 'TestPath');
|
||||||
|
assert.strictEqual(unquoteText('\'TestPath\"'), 'TestPath');
|
||||||
|
assert.strictEqual(unquoteText('\"TestPath\''), 'TestPath');
|
||||||
|
assert.strictEqual(unquoteText('\"Tes"tPa"th\"'), 'Tes"tPa"th');
|
||||||
|
assert.strictEqual(unquoteText('\"TestPath'), '\"TestPath');
|
||||||
|
assert.strictEqual(unquoteText('\'TestPath'), '\'TestPath');
|
||||||
|
assert.strictEqual(unquoteText('TestPath\"'), 'TestPath\"');
|
||||||
|
assert.strictEqual(unquoteText('TestPath\''), 'TestPath\'');
|
||||||
|
assert.strictEqual(unquoteText(undefined), undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Should return file link properly', async function (): Promise<void> {
|
test('Should return file link properly', async function (): Promise<void> {
|
||||||
@@ -124,9 +138,9 @@ suite('Link Callout Dialog', function (): void {
|
|||||||
// And insert the dialog
|
// And insert the dialog
|
||||||
linkCalloutDialog.insert();
|
linkCalloutDialog.insert();
|
||||||
let result = await deferred.promise;
|
let result = await deferred.promise;
|
||||||
assert.equal(result.insertUnescapedLinkLabel, defaultLabel, 'Label not returned correctly');
|
assert.strictEqual(result.insertUnescapedLinkLabel, defaultLabel, 'Label not returned correctly');
|
||||||
assert.equal(result.insertUnescapedLinkUrl, sampleUrl, 'URL not returned correctly');
|
assert.strictEqual(result.insertUnescapedLinkUrl, sampleUrl, 'URL not returned correctly');
|
||||||
assert.equal(result.insertEscapedMarkdown, `[${defaultLabel}](${sampleUrl})`, 'Markdown not returned correctly');
|
assert.strictEqual(result.insertEscapedMarkdown, `[${defaultLabel}](${sampleUrl})`, 'Markdown not returned correctly');
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user