Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates tsec and rewrites sinks assignement #112069

Merged
merged 2 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
"source-map": "^0.4.4",
"style-loader": "^1.0.0",
"ts-loader": "^4.4.2",
"tsec": "googleinterns/tsec",
"tsec": "googleinterns/tsec#630b53fe2b23815c28dd219119cc98dbd59e29b2",
"typescript": "^4.2.0-dev.20201119",
"typescript-formatter": "7.1.0",
"underscore": "^1.8.2",
Expand Down Expand Up @@ -197,4 +197,4 @@
"windows-mutex": "0.3.0",
"windows-process-tree": "0.2.4"
}
}
}
2 changes: 1 addition & 1 deletion src/vs/base/browser/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1385,7 +1385,7 @@ export function safeInnerHtml(node: HTMLElement, value: string): void {
}, ['class', 'id', 'role', 'tabindex']);

const html = _ttpSafeInnerHtml?.createHTML(value, options) ?? insane(value, options);
node.innerHTML = html as unknown as string;
node.innerHTML = html as string;
}

/**
Expand Down
10 changes: 3 additions & 7 deletions src/vs/base/browser/markdownRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export function renderMarkdown(markdown: IMarkdownString, options: MarkdownRende
const renderedMarkdown = marked.parse(value, markedOptions);

// sanitize with insane
element.innerHTML = sanitizeRenderedMarkdown(markdown, renderedMarkdown);
element.innerHTML = sanitizeRenderedMarkdown(markdown, renderedMarkdown) as string;

// signal that async code blocks can be now be inserted
signalInnerHTML!();
Expand All @@ -261,13 +261,9 @@ export function renderMarkdown(markdown: IMarkdownString, options: MarkdownRende
function sanitizeRenderedMarkdown(
options: { isTrusted?: boolean },
renderedMarkdown: string,
): string {
): string | TrustedHTML {
const insaneOptions = getInsaneOptions(options);
if (_ttpInsane) {
return _ttpInsane.createHTML(renderedMarkdown, insaneOptions) as unknown as string;
} else {
return insane(renderedMarkdown, insaneOptions);
}
return _ttpInsane?.createHTML(renderedMarkdown, insaneOptions) ?? insane(renderedMarkdown, insaneOptions);
}

function getInsaneOptions(options: { readonly isTrusted?: boolean }): InsaneOptions {
Expand Down
4 changes: 1 addition & 3 deletions src/vs/editor/browser/core/markdownRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ export class MarkdownRenderer {

const element = document.createElement('span');

element.innerHTML = MarkdownRenderer._ttpTokenizer
? MarkdownRenderer._ttpTokenizer.createHTML(value, tokenization) as unknown as string
: tokenizeToString(value, tokenization);
element.innerHTML = (MarkdownRenderer._ttpTokenizer?.createHTML(value, tokenization) ?? tokenizeToString(value, tokenization)) as string;

// use "good" font
let fontFamily = this._options.codeBlockFontFamily;
Expand Down
4 changes: 2 additions & 2 deletions src/vs/editor/browser/view/domLineBreaksComputer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ function createLineBreaks(requests: string[], fontInfo: FontInfo, tabSize: numbe
allVisibleColumns[i] = tmp[1];
}
const html = sb.build();
const trustedhtml = ttPolicy ? ttPolicy.createHTML(html) : html;
containerDomNode.innerHTML = trustedhtml as unknown as string;
const trustedhtml = ttPolicy?.createHTML(html) ?? html;
containerDomNode.innerHTML = trustedhtml as string;

containerDomNode.style.position = 'absolute';
containerDomNode.style.top = '10000';
Expand Down
14 changes: 7 additions & 7 deletions src/vs/editor/browser/view/viewLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,15 +506,15 @@ class ViewLayerRenderer<T extends IVisibleLine> {
ctx.lines.splice(removeIndex, removeCount);
}

private _finishRenderingNewLines(ctx: IRendererContext<T>, domNodeIsEmpty: boolean, newLinesHTML: string, wasNew: boolean[]): void {
private _finishRenderingNewLines(ctx: IRendererContext<T>, domNodeIsEmpty: boolean, newLinesHTML: string | TrustedHTML, wasNew: boolean[]): void {
if (ViewLayerRenderer._ttPolicy) {
newLinesHTML = ViewLayerRenderer._ttPolicy.createHTML(newLinesHTML) as unknown as string; // explains the ugly casts -> https://github.com/microsoft/vscode/issues/106396#issuecomment-692625393
newLinesHTML = ViewLayerRenderer._ttPolicy.createHTML(newLinesHTML as string);
}
const lastChild = <HTMLElement>this.domNode.lastChild;
if (domNodeIsEmpty || !lastChild) {
this.domNode.innerHTML = newLinesHTML;
this.domNode.innerHTML = newLinesHTML as string; // explains the ugly casts -> https://github.com/microsoft/vscode/issues/106396#issuecomment-692625393;
} else {
lastChild.insertAdjacentHTML('afterend', newLinesHTML);
lastChild.insertAdjacentHTML('afterend', newLinesHTML as string);
}

let currChild = <HTMLElement>this.domNode.lastChild;
Expand All @@ -527,13 +527,13 @@ class ViewLayerRenderer<T extends IVisibleLine> {
}
}

private _finishRenderingInvalidLines(ctx: IRendererContext<T>, invalidLinesHTML: string, wasInvalid: boolean[]): void {
private _finishRenderingInvalidLines(ctx: IRendererContext<T>, invalidLinesHTML: string | TrustedHTML, wasInvalid: boolean[]): void {
const hugeDomNode = document.createElement('div');

if (ViewLayerRenderer._ttPolicy) {
invalidLinesHTML = ViewLayerRenderer._ttPolicy.createHTML(invalidLinesHTML) as unknown as string;
invalidLinesHTML = ViewLayerRenderer._ttPolicy.createHTML(invalidLinesHTML as string);
}
hugeDomNode.innerHTML = invalidLinesHTML;
hugeDomNode.innerHTML = invalidLinesHTML as string;

for (let i = 0; i < ctx.linesLength; i++) {
const line = ctx.lines[i];
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/browser/widget/diffEditorWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2370,7 +2370,7 @@ class InlineViewZonesComputer extends ViewZonesComputer {

const html = sb.build();
const trustedhtml = ttPolicy ? ttPolicy.createHTML(html) : html;
domNode.innerHTML = trustedhtml as unknown as string;
domNode.innerHTML = trustedhtml as string;
viewZone.minWidthInPx = (maxCharsPerLine * typicalHalfwidthCharacterWidth);

if (viewLineCounts) {
Expand Down
4 changes: 2 additions & 2 deletions src/vs/editor/standalone/browser/colorizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export class Colorizer {
let text = domNode.firstChild ? domNode.firstChild.nodeValue : '';
domNode.className += ' ' + theme;
let render = (str: string) => {
const trustedhtml = ttPolicy ? ttPolicy.createHTML(str) : str;
domNode.innerHTML = trustedhtml as unknown as string;
const trustedhtml = ttPolicy?.createHTML(str) ?? str;
domNode.innerHTML = trustedhtml as string;
};
return this.colorize(modeService, text || '', mimeType, options).then(render, (err) => console.error(err));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ class EditorTextRenderer {
const element = DOM.$('div', { style });

const linesHtml = this.getRichTextLinesAsHtml(model, modelRange, colorMap);
element.innerHTML = linesHtml as unknown as string;
element.innerHTML = linesHtml as string;
return element;
}

Expand Down
16 changes: 11 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@
integrity sha512-u/SJDyXwuihpwjXy7hOOghagLEV1KdAST6syfnOk6QZAMzZuWZqXy5aYYZbh8Jdpd4escVFP0MvftHNDb9pruA==

"@types/node@^13.13.5":
version "13.13.28"
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.13.28.tgz#b6d0628b0371d6c629d729c98322de314b640219"
integrity sha512-EM/qFeRH8ZCD+TlsaIPULyyFm9vOhFIvgskY2JmHbEsWsOPgN+rtjSXrcHGgJpob4Nu17VfO95FKewr0XY7iOQ==
version "13.13.34"
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.13.34.tgz#c9300a1b6560d90817fb2bba650e250116a575f9"
integrity sha512-g8D1HF2dMDKYSDl5+79izRwRgNPsSynmWMbj50mj7GZ0b7Lv4p8EmZjbo3h0h+6iLr6YmVz9VnF6XVZ3O6V1Ug==

"@types/semver@^5.4.0", "@types/semver@^5.5.0":
version "5.5.0"
Expand Down Expand Up @@ -9520,11 +9520,12 @@ ts-loader@^4.4.2:
micromatch "^3.1.4"
semver "^5.0.1"

tsec@googleinterns/tsec:
tsec@googleinterns/tsec#630b53fe2b23815c28dd219119cc98dbd59e29b2:
version "0.0.1"
resolved "https://codeload.github.com/googleinterns/tsec/tar.gz/bec3c527789daa9151be2bc8471cfefa4f44d167"
resolved "https://codeload.github.com/googleinterns/tsec/tar.gz/630b53fe2b23815c28dd219119cc98dbd59e29b2"
dependencies:
"@types/node" "^13.13.5"
typescript "^3.9.2"

tslib@^1.8.1, tslib@^1.9.0:
version "1.9.3"
Expand Down Expand Up @@ -9603,6 +9604,11 @@ typescript@^2.6.2:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.6.2.tgz#3c5b6fd7f6de0914269027f03c0946758f7673a4"
integrity sha1-PFtv1/beCRQmkCfwPAlGdY92c6Q=

typescript@^3.9.2:
version "3.9.7"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa"
integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==

typescript@^4.2.0-dev.20201119:
version "4.2.0-dev.20201119"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.0-dev.20201119.tgz#d4a43511cd9931adac05e1a47b6425f6b0e76cc3"
Expand Down