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

refactor: prepare to use the html/template version of the OSS HTML [IDE-326] #482

Merged
merged 1 commit into from
Jul 8, 2024
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Snyk Security Changelog

## [2.12.4]
### [2.13.1]
- Refactor the Suggestion Panel for OSS so it's more secure and will be supported in other IDEs

## [2.13.0]
- Fix `.suggestion` class to ensure it is scrollable and not overlapped by the `.suggestion-actions` fixed element. This change prevents the suggestion content from being hidden.
- transmit required protocol version to language server
- Remove unused stylesheet and refactor stylesheets
Expand Down
24 changes: 20 additions & 4 deletions src/snyk/snykOss/providers/ossDetailPanelProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { IVSCodeLanguages } from '../../common/vscode/languages';
import { IVSCodeWindow } from '../../common/vscode/window';
import { IVSCodeWorkspace } from '../../common/vscode/workspace';
import { messages } from '../constants/messages';
import { readFileSync } from 'fs';

export class OssDetailPanelProvider
extends WebviewProvider<Issue<OssIssueData>>
Expand Down Expand Up @@ -78,17 +79,32 @@ export class OssDetailPanelProvider
}, {});

const displayMode = 'dark';

let html = issue.additionalData.details;

// Add the style
const ideStylePath = vscode.Uri.joinPath(
vscode.Uri.file(this.context.extensionPath),
'media',
'views',
'oss',
'suggestion',
'suggestion.css',
);
const ideStyle = readFileSync(ideStylePath.fsPath, 'utf8');
const nonce = getNonce();

// TODO: remove after the stable CLI release at the end of cycle 5
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder to create a ticket to remove this code when we fully enable this HTML panel after the end of cycle 5 and the stable release of the CLI

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const styleUri = this.getWebViewUri('media', 'views', 'oss', 'suggestion', 'suggestion.css');
const headerEndValue = `<link href="${styleUri}" rel="stylesheet">`;
const serverityIconName = `${displayMode}-${issue.severity}-severity`;
const nonce = getNonce();

let html = issue.additionalData.details;
html = html.replace('${headerEnd}', headerEndValue);
html = html.replaceAll('${cspSource}', this.panel.webview.cspSource);
html = html.replaceAll('${nonce}', nonce);
html = html.replace('${severityIcon}', images[serverityIconName]);
html = html.replace('${learnIcon}', images['learn-icon']);
// TODO: end remove
html = html.replace('${ideStyle}', '<style nonce=${nonce}>' + ideStyle + '</style>');
html = html.replaceAll('${nonce}', nonce);
html = html.replaceAll(/\$\{\w+\}/g, '');
this.panel.webview.html = html;
this.panel.iconPath = vscode.Uri.joinPath(
Expand Down
Loading