Skip to content

Commit 90f5681

Browse files
authored
fix: purls encoding (CM-1218) (#4201)
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent 730d5cf commit 90f5681

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

backend/src/api/public/v1/packages/batchGetStewardship.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,33 @@ const MAX_PURLS = 100
1313

1414
const bodySchema = z.object({
1515
purls: z
16-
.array(z.string().trim().min(1))
16+
.array(
17+
z
18+
.string()
19+
.trim()
20+
.min(1)
21+
.refine((v) => v.startsWith('pkg:'), { message: 'each purl must start with pkg:' }),
22+
)
1723
.min(1)
1824
.max(MAX_PURLS, `Maximum ${MAX_PURLS} purls per request`),
1925
})
2026

2127
export async function batchGetStewardship(req: Request, res: Response): Promise<void> {
22-
const { purls } = validateOrThrow(bodySchema, req.body)
28+
const { purls: rawPurls } = validateOrThrow(bodySchema, req.body)
29+
const normalizedPurls = rawPurls.map((p) => p.replace(/@/g, '%40'))
2330

2431
const qx = await getPackagesQx()
25-
const rows = await getPackagesByStewardshipPurls(qx, purls)
32+
const rows = await getPackagesByStewardshipPurls(qx, normalizedPurls)
2633

2734
const byPurl = new Map(rows.map((r) => [r.purl, r]))
2835

2936
const packages: Record<string, StewardshipSummary | null> = {}
30-
for (const purl of purls) {
31-
const row = byPurl.get(purl)
37+
for (let i = 0; i < rawPurls.length; i++) {
38+
const row = byPurl.get(normalizedPurls[i])
3239
if (!row) {
33-
packages[purl] = null
40+
packages[rawPurls[i]] = null
3441
} else {
35-
packages[purl] = {
42+
packages[rawPurls[i]] = {
3643
name: row.name,
3744
ecosystem: row.ecosystem,
3845
lifecycle: null,

backend/src/api/public/v1/packages/getPackage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ const querySchema = z.object({
1515
.string()
1616
.trim()
1717
.min(1)
18-
.refine((v) => v.startsWith('pkg:'), { message: 'purl must start with pkg:' }),
18+
.refine((v) => v.startsWith('pkg:'), { message: 'purl must start with pkg:' })
19+
.transform((v) => v.replace(/@/g, '%40')),
1920
})
2021

2122
export async function getPackage(req: Request, res: Response): Promise<void> {

0 commit comments

Comments
 (0)