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

fix: add flag to track encoding state of example lines #428

Merged
merged 1 commit into from
Feb 5, 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Snyk Security - Code and Open Source Dependencies Changelog

## [2.2.3]

### Fixed

- Snyk Code: Added `isExampleLineEncoded` boolean flag to `CommitChangeLine` type to prevent re-encoding strings in the UI of the example code blocks.

## [2.2.2]

### Fixed
Expand Down
1 change: 1 addition & 0 deletions src/snyk/common/languageServer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type CommitChangeLine = {
line: string;
lineNumber: number;
lineChange: 'removed' | 'added' | 'none';
isExampleLineEncoded?: boolean;
};
export type Marker = {
msg: Point;
Expand Down
19 changes: 12 additions & 7 deletions src/snyk/snykCode/utils/htmlEncoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ import he from 'he';
import { ExampleCommitFix } from '../../common/languageServer/types';

export const encodeExampleCommitFixes = (exampleCommitFixes: ExampleCommitFix[]): ExampleCommitFix[] => {
return exampleCommitFixes.map(exampleCommitFixes => {
return exampleCommitFixes.map(example => {
return {
...exampleCommitFixes,
lines: exampleCommitFixes.lines.map(line => {
return {
...line,
line: he.encode(line.line),
};
...example,
lines: example.lines.map(commitLine => {
if (!commitLine.isExampleLineEncoded) {
return {
...commitLine,
line: he.encode(commitLine.line),
isExampleLineEncoded: true,
};
}

return commitLine;
}),
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
line: string;
lineNumber: number;
lineChange: 'removed' | 'added' | 'none';
isExampleLineEncoded?: boolean;
};
type Marker = {
msg: Point;
Expand Down Expand Up @@ -61,7 +62,7 @@
text: string;
};

const vscode = acquireVsCodeApi();

Check warning on line 65 in src/snyk/snykCode/views/suggestion/codeSuggestionWebviewScript.ts

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-latest)

Unsafe assignment of an `any` value

Check warning on line 65 in src/snyk/snykCode/views/suggestion/codeSuggestionWebviewScript.ts

View workflow job for this annotation

GitHub Actions / Build and Test (macos-latest)

Unsafe assignment of an `any` value

Check warning on line 65 in src/snyk/snykCode/views/suggestion/codeSuggestionWebviewScript.ts

View workflow job for this annotation

GitHub Actions / Build and Test (windows-latest)

Unsafe assignment of an `any` value

const elements = {
readMoreBtnElem: document.querySelector('.read-more-btn') as HTMLElement,
Expand Down Expand Up @@ -97,7 +98,7 @@
let exampleCount = 0;

// Try to restore the previous state
let lesson: Lesson | null = vscode.getState()?.lesson || null;

Check warning on line 101 in src/snyk/snykCode/views/suggestion/codeSuggestionWebviewScript.ts

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-latest)

Unsafe assignment of an `any` value

Check warning on line 101 in src/snyk/snykCode/views/suggestion/codeSuggestionWebviewScript.ts

View workflow job for this annotation

GitHub Actions / Build and Test (macos-latest)

Unsafe assignment of an `any` value

Check warning on line 101 in src/snyk/snykCode/views/suggestion/codeSuggestionWebviewScript.ts

View workflow job for this annotation

GitHub Actions / Build and Test (windows-latest)

Unsafe assignment of an `any` value
fillLearnLink();
let suggestion: Suggestion | null = vscode.getState()?.suggestion || null;
showCurrentSuggestion();
Expand Down
Loading