mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-29 01:25:37 -05:00
check for encoded components (#18231)
* check for encoded components * address comments * relocate and simplify test * move encodeUrl to notebookLinkHandler * added comments * add containsEncodedUri to network.ts
This commit is contained in:
@@ -278,8 +278,8 @@ export class MarkdownToolbarComponent extends AngularDisposable {
|
||||
// Otherwise, re-focus on the output element, and insert the link directly.
|
||||
this.output?.nativeElement?.focus();
|
||||
// Need to encode URI here in order for user to click the proper encoded link in WYSIWYG
|
||||
let encodedLinkURL = encodeURI(linkUrl);
|
||||
document.execCommand('insertHTML', false, `<a href="${encodedLinkURL}" title="${encodedLinkURL}" is-encoded="true" is-absolute=${notebookLink.isAbsolutePath}>${escape(linkCalloutResult?.insertUnescapedLinkLabel)}</a>`);
|
||||
let encodedLinkURL = notebookLink.getEncodedLinkUrl();
|
||||
document.execCommand('insertHTML', false, `<a href="${encodedLinkURL}" title="${linkUrl}" is-encoded="true" is-absolute=${notebookLink.isAbsolutePath}>${escape(linkCalloutResult?.insertUnescapedLinkLabel)}</a>`);
|
||||
return;
|
||||
}
|
||||
} else if (type === MarkdownButtonType.IMAGE_PREVIEW) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import * as path from 'vs/base/common/path';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { replaceInvalidLinkPath } from 'sql/workbench/contrib/notebook/common/utils';
|
||||
import { isWindows } from 'vs/base/common/platform';
|
||||
import { containsEncodedUriComponentReservedCharacters } from 'sql/base/common/network';
|
||||
|
||||
const useAbsolutePathConfigName = 'notebook.useAbsoluteFilePaths';
|
||||
|
||||
@@ -118,6 +119,24 @@ export class NotebookLinkHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get encoded url, Gets the link URI-encoded link URL
|
||||
* (https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/encodeURI)
|
||||
* @returns the encoded url
|
||||
*/
|
||||
public getEncodedLinkUrl(): string | undefined {
|
||||
if (typeof this._link === 'string') {
|
||||
// Need to encode URI here in order for user to click the proper encoded link in WYSIWYG
|
||||
// skip encoding it if it's already encoded
|
||||
if (!containsEncodedUriComponentReservedCharacters(this._link)) {
|
||||
return encodeURI(this._link);
|
||||
}
|
||||
return this._link;
|
||||
}
|
||||
// since we only handle strings that come from call out dialogs
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a URI for for a link with a anchor (#)
|
||||
* @param node is the HTMLAnchorElement of the target notebook
|
||||
|
||||
@@ -43,4 +43,3 @@ export function highlightSelectedText(): void {
|
||||
document.execCommand('hiliteColor', false, 'Yellow');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user