Skip to content

Commit 743d0a9

Browse files
heiskrCopilot
andauthored
Remove two unmaintained packages: csp-parse and http-status-code (#63236)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 35abb1df-6285-443c-892a-30c594d2d64c
1 parent b729e5e commit 743d0a9

6 files changed

Lines changed: 19 additions & 115 deletions

File tree

‎package-lock.json‎

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

‎package.json‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@
295295
"change-case": "^5.4.4",
296296
"commander": "^15.0.0",
297297
"cross-env": "^10.1.0",
298-
"csp-parse": "0.0.2",
299298
"csv-parse": "7.0.0",
300299
"domhandler": "^5.0.3",
301300
"escape-string-regexp": "5.0.0",
@@ -317,7 +316,6 @@
317316
"globals": "^17.3.0",
318317
"gpt-tokenizer": "^4.0.0",
319318
"graphql": "^16.12.0",
320-
"http-status-code": "^2.1.0",
321319
"husky": "^9.1.7",
322320
"is-svg": "6.0.0",
323321
"jiti": "^2.6.1",

‎src/frame/tests/server.ts‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// csp-parse doesn't have TypeScript types
2-
import CspParse from 'csp-parse'
31
import { beforeAll, describe, expect, test, vi } from 'vitest'
42

53
import enterpriseServerReleases from '@/versions/lib/enterprise-server-releases'
@@ -17,6 +15,21 @@ interface Category {
1715
published_articles: string[]
1816
}
1917

18+
// Parses a Content-Security-Policy header into its directives. Mirrors the
19+
// behavior of the unmaintained `csp-parse` package it replaces: the policy is
20+
// lowercased, split on `;`, and each directive's values are returned as a
21+
// space-joined string, or an empty string when the directive is absent.
22+
function parseCsp(policy: string) {
23+
const directives = new Map<string, string>()
24+
for (const part of (policy || '').toLowerCase().split(';')) {
25+
const [name, ...values] = part.trim().split(/\s+/)
26+
if (name) directives.set(name, values.join(' '))
27+
}
28+
return {
29+
get: (directive: string) => directives.get(directive) || '',
30+
}
31+
}
32+
2033
describe('server', () => {
2134
vi.setConfig({ testTimeout: 60 * 1000 })
2235

@@ -50,7 +63,7 @@ describe('server', () => {
5063
expect(res.statusCode).toBe(200)
5164
expect('content-security-policy' in res.headers).toBe(true)
5265

53-
const csp = new CspParse(res.headers['content-security-policy'])
66+
const csp = parseCsp(res.headers['content-security-policy'])
5467
expect(csp.get('default-src')).toBe("'none'")
5568

5669
expect(csp.get('font-src').includes("'self'")).toBe(true)

‎src/rest/scripts/utils/operation.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import httpStatusCodes from 'http-status-code'
1+
import { STATUS_CODES } from 'node:http'
2+
23
import { get, isPlainObject } from 'lodash-es'
34
import { parseTemplate } from 'url-template'
45
import mergeAllOf from 'json-schema-merge-allof'
@@ -131,7 +132,7 @@ export default class Operation {
131132
responseKeys.map(async (responseCode) => {
132133
const response = responses[responseCode]
133134
const httpStatusCode = responseCode
134-
const httpStatusMessage = httpStatusCodes.getMessage(Number(responseCode), 'HTTP/2')
135+
const httpStatusMessage = STATUS_CODES[Number(responseCode)] || 'Unknown'
135136
// The OpenAPI should be updated to provide better descriptions, but
136137
// until then, we can catch some known generic descriptions and replace
137138
// them with the default http status message.

‎src/tests/declarations.d.ts‎

Lines changed: 0 additions & 6 deletions
This file was deleted.

‎src/types/http-status-code.d.ts‎

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)