Skip to content

Commit

Permalink
fix: add flag to track encoding state of example lines (#428)
Browse files Browse the repository at this point in the history
Ensure `htmlEncoder` function only encodes each line once,
preventing double encoding on subsequent function calls.
  • Loading branch information
cat2608 authored Feb 5, 2024
1 parent c9f170e commit 2e65f47
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
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 @@ declare const acquireVsCodeApi: any;
line: string;
lineNumber: number;
lineChange: 'removed' | 'added' | 'none';
isExampleLineEncoded?: boolean;
};
type Marker = {
msg: Point;
Expand Down

0 comments on commit 2e65f47

Please sign in to comment.