Skip to content

Commit

Permalink
Fixes #1258: Support list of commands for trusted markdown. (#1259)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaeumer authored Jun 23, 2023
1 parent 43b7c72 commit f932967
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 25 deletions.
16 changes: 8 additions & 8 deletions client-node-tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions client-node-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"description": "",
"version": "0.0.1",
"engines": {
"vscode": "^1.68.0"
"vscode": "^1.79.0"
},
"categories": [
"Other"
Expand Down Expand Up @@ -38,7 +38,7 @@
"@types/minimatch": "^3.0.5",
"@types/sinon": "^10.0.2",
"@types/uuid": "^8.3.1",
"@types/vscode": "1.68.0",
"@types/vscode": "1.79.0",
"find-process": "^1.4.7",
"glob": "^7.1.7",
"sinon": "^11.1.2",
Expand Down
16 changes: 8 additions & 8 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Microsoft Corporation",
"license": "MIT",
"engines": {
"vscode": "^1.77.0"
"vscode": "^1.79.0"
},
"repository": {
"type": "git",
Expand All @@ -24,7 +24,7 @@
"devDependencies": {
"@types/minimatch": "^3.0.5",
"@types/semver": "^7.3.10",
"@types/vscode": "1.68.0",
"@types/vscode": "1.79.0",
"shx": "^0.3.4"
},
"dependencies": {
Expand Down
19 changes: 15 additions & 4 deletions client/src/common/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ export type LanguageClientOptions = {
maxRestartCount?: number;
};
markdown?: {
isTrusted?: boolean;
isTrusted?: boolean | { readonly enabledCommands: readonly string[] };
supportHtml?: boolean;
};
} & $NotebookDocumentOptions & $DiagnosticPullOptions & $ConfigurationOptions;
Expand Down Expand Up @@ -410,10 +410,21 @@ type ResolvedClientOptions = {
maxRestartCount?: number;
};
markdown: {
isTrusted: boolean;
isTrusted: boolean | { readonly enabledCommands: readonly string[] };
supportHtml: boolean;
};
} & Required<$NotebookDocumentOptions> & Required<$DiagnosticPullOptions>;
namespace ResolvedClientOptions {
export function sanitizeIsTrusted(isTrusted?: boolean | { readonly enabledCommands: readonly string[] }): boolean | { readonly enabledCommands: readonly string[] } {
if (isTrusted === undefined || isTrusted === null) {
return false;
}
if ((typeof isTrusted === 'boolean') || (typeof isTrusted === 'object' && isTrusted !== null && Is.stringArray(isTrusted.enabledCommands))) {
return isTrusted;
}
return false;
}
}

class DefaultErrorHandler implements ErrorHandler {

Expand Down Expand Up @@ -527,9 +538,9 @@ export abstract class BaseLanguageClient implements FeatureClient<Middleware, La

clientOptions = clientOptions || {};

const markdown = { isTrusted: false, supportHtml: false };
const markdown: ResolvedClientOptions['markdown'] = { isTrusted: false, supportHtml: false };
if (clientOptions.markdown !== undefined) {
markdown.isTrusted = clientOptions.markdown.isTrusted === true;
markdown.isTrusted = ResolvedClientOptions.sanitizeIsTrusted(clientOptions.markdown.isTrusted);
markdown.supportHtml = clientOptions.markdown.supportHtml === true;
}

Expand Down
2 changes: 1 addition & 1 deletion client/src/common/protocolConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ namespace CodeBlock {
}
}

export function createConverter(uriConverter: URIConverter | undefined, trustMarkdown: boolean, supportHtml: boolean): Converter {
export function createConverter(uriConverter: URIConverter | undefined, trustMarkdown: boolean | { readonly enabledCommands: readonly string[] }, supportHtml: boolean): Converter {

const nullConverter = (value: string) => code.Uri.parse(value);

Expand Down

0 comments on commit f932967

Please sign in to comment.