Skip to content

Commit 3c912a0

Browse files
authored
deps: remove "sanitize-html" dependency #4446
Problem: This package was added in 9e8976b to guard against unexpected server response, but it has a lot more features (and transitive dependencies) that we aren't using. It's also adding a maintenance cost: #4435 Solution: - Use `encodeHTML` instead. - Remove unnecessary dependencies.
1 parent 4c502c3 commit 3c912a0

File tree

4 files changed

+16
-118
lines changed

4 files changed

+16
-118
lines changed

package-lock.json

Lines changed: 8 additions & 108 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/toolkit/package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4293,7 +4293,6 @@
42934293
"@types/node-fetch": "^2.6.8",
42944294
"@types/prismjs": "^1.26.0",
42954295
"@types/readline-sync": "^1.4.3",
4296-
"@types/sanitize-html": "2.3.1",
42974296
"@types/semver": "^7.5.0",
42984297
"@types/sinon": "^10.0.5",
42994298
"@types/sinonjs__fake-timers": "^8.1.2",
@@ -4321,12 +4320,12 @@
43214320
"sass-loader": "^12.6.0",
43224321
"sinon": "^14.0.0",
43234322
"style-loader": "^3.3.1",
4323+
"ts-node": "^10.9.1",
4324+
"typescript": "^5.0.4",
43244325
"umd-compat-loader": "^2.1.2",
43254326
"vue-loader": "^17.2.2",
43264327
"vue-style-loader": "^4.1.3",
4327-
"webfont": "^11.2.26",
4328-
"typescript": "^5.0.4",
4329-
"ts-node": "^10.9.1"
4328+
"webfont": "^11.2.26"
43304329
},
43314330
"dependencies": {
43324331
"@amzn/codewhisperer-streaming": "file:../../src.gen/@amzn/codewhisperer-streaming",
@@ -4367,7 +4366,6 @@
43674366
"mime-types": "^2.1.32",
43684367
"node-fetch": "^2.7.0",
43694368
"portfinder": "^1.0.32",
4370-
"sanitize-html": "^2.3.3",
43714369
"semver": "^7.5.4",
43724370
"strip-ansi": "^5.2.0",
43734371
"tcp-port-used": "^1.0.1",

packages/toolkit/src/amazonqFeatureDev/session/sessionState.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import sanitizeHtml from 'sanitize-html'
76
import * as vscode from 'vscode'
87
import { ToolkitError } from '../../shared/errors'
98
import { getLogger } from '../../shared/logger'
@@ -12,6 +11,7 @@ import { IllegalStateTransition, UserMessageNotFoundError } from '../errors'
1211
import { SessionState, SessionStateAction, SessionStateConfig, SessionStateInteraction } from '../types'
1312
import { prepareRepoData } from '../util/files'
1413
import { uploadCode } from '../util/upload'
14+
import { encodeHTML } from '../../shared/utilities/textUtilities'
1515

1616
export class ConversationNotStartedState implements Omit<SessionState, 'uploadId'> {
1717
public tokenSource: vscode.CancellationTokenSource
@@ -90,10 +90,9 @@ export class RefinementState implements SessionState {
9090
action.msg
9191
)
9292

93-
this.approach = sanitizeHtml(
93+
this.approach = encodeHTML(
9494
approach ??
95-
'There has been a problem generating an approach. Please open a conversation in a new tab',
96-
{}
95+
'There has been a problem generating an approach. Please open a conversation in a new tab'
9796
)
9897
getLogger().debug(`Approach response: %O`, this.approach)
9998

packages/toolkit/src/test/amazonqFeatureDev/session/sessionState.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ describe('sessionState', () => {
135135
const state = new RefinementState(testConfig, invalidHTMLApproach, tabId, 0)
136136
const result = await state.interact(testAction)
137137

138-
const expectedApproach = `<h1>hello world</h1>`
138+
const expectedApproach =
139+
'&lt;head&gt;&lt;script src="https://foo"&gt;&lt;/script&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;hello world&lt;/h1&gt;&lt;/body&gt;'
139140
assert.deepStrictEqual(result, {
140141
nextState: new RefinementState(testConfig, expectedApproach, tabId, 1),
141142
interaction: {

0 commit comments

Comments
 (0)