Skip to content

Commit e218dde

Browse files
committed
Fix CI failure in Run CI Pipeline / 📊 Coverage Report (run 18681053444)
1 parent 1e51d50 commit e218dde

File tree

4 files changed

+46
-44
lines changed

4 files changed

+46
-44
lines changed

src/normalize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function qualifiersToEntries(
134134
if (isObject(rawQualifiers)) {
135135
// URLSearchParams instances have an "entries" method that returns an iterator
136136
const rawQualifiersObj = rawQualifiers as QualifiersObject | URLSearchParams
137-
const entriesProperty = (rawQualifiersObj as QualifiersObject).entries
137+
const entriesProperty = (rawQualifiersObj as QualifiersObject)['entries']
138138
return typeof entriesProperty === 'function'
139139
? (ReflectApply(entriesProperty, rawQualifiersObj, []) as Iterable<
140140
[string, string]

src/package-url.ts

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -99,47 +99,47 @@ class PackageURL {
9999
rawSubpath: unknown,
100100
) {
101101
const type = isNonEmptyString(rawType)
102-
? (PurlComponent.type?.normalize as ComponentNormalizer)?.(rawType)
102+
? (PurlComponent['type']?.['normalize'] as ComponentNormalizer)?.(rawType)
103103
: rawType
104-
;(PurlComponent.type?.validate as ComponentValidator)?.(type, true)
104+
;(PurlComponent['type']?.['validate'] as ComponentValidator)?.(type, true)
105105

106106
const namespace = isNonEmptyString(rawNamespace)
107-
? (PurlComponent.namespace?.normalize as ComponentNormalizer)?.(
107+
? (PurlComponent['namespace']?.['normalize'] as ComponentNormalizer)?.(
108108
rawNamespace,
109109
)
110110
: rawNamespace
111-
;(PurlComponent.namespace?.validate as ComponentValidator)?.(
111+
;(PurlComponent['namespace']?.['validate'] as ComponentValidator)?.(
112112
namespace,
113113
true,
114114
)
115115

116116
const name = isNonEmptyString(rawName)
117-
? (PurlComponent.name?.normalize as ComponentNormalizer)?.(rawName)
117+
? (PurlComponent['name']?.['normalize'] as ComponentNormalizer)?.(rawName)
118118
: rawName
119-
;(PurlComponent.name?.validate as ComponentValidator)?.(name, true)
119+
;(PurlComponent['name']?.['validate'] as ComponentValidator)?.(name, true)
120120

121121
const version = isNonEmptyString(rawVersion)
122-
? (PurlComponent.version?.normalize as ComponentNormalizer)?.(rawVersion)
122+
? (PurlComponent['version']?.['normalize'] as ComponentNormalizer)?.(rawVersion)
123123
: rawVersion
124-
;(PurlComponent.version?.validate as ComponentValidator)?.(version, true)
124+
;(PurlComponent['version']?.['validate'] as ComponentValidator)?.(version, true)
125125

126126
const qualifiers =
127127
typeof rawQualifiers === 'string' || isObject(rawQualifiers)
128128
? (
129-
PurlComponent.qualifiers?.normalize as (
129+
PurlComponent['qualifiers']?.['normalize'] as (
130130
_value: string | QualifiersObject,
131131
) => Record<string, string> | undefined
132132
)?.(rawQualifiers as string | QualifiersObject)
133133
: rawQualifiers
134-
;(PurlComponent.qualifiers?.validate as ComponentValidator)?.(
134+
;(PurlComponent['qualifiers']?.['validate'] as ComponentValidator)?.(
135135
qualifiers,
136136
true,
137137
)
138138

139139
const subpath = isNonEmptyString(rawSubpath)
140-
? (PurlComponent.subpath?.normalize as ComponentNormalizer)?.(rawSubpath)
140+
? (PurlComponent['subpath']?.['normalize'] as ComponentNormalizer)?.(rawSubpath)
141141
: rawSubpath
142-
;(PurlComponent.subpath?.validate as ComponentValidator)?.(subpath, true)
142+
;(PurlComponent['subpath']?.['validate'] as ComponentValidator)?.(subpath, true)
143143

144144
this.type = type as string
145145
this.name = name as string
@@ -156,9 +156,9 @@ class PackageURL {
156156

157157
const typeHelpers = PurlType[type as string]
158158
if (typeHelpers) {
159-
;(typeHelpers?.normalize as (_purl: PackageURL) => void)?.(this)
159+
;(typeHelpers?.['normalize'] as (_purl: PackageURL) => void)?.(this)
160160
;(
161-
typeHelpers?.validate as (
161+
typeHelpers?.['validate'] as (
162162
_purl: PackageURL,
163163
_throws: boolean,
164164
) => boolean
@@ -222,19 +222,19 @@ class PackageURL {
222222
type?: string | undefined
223223
version?: string | undefined
224224
} = this
225-
/* c8 ignore next - Type encoder uses default PurlComponentEncoder, never returns null/undefined. */ let purlStr = `pkg:${(PurlComponent.type?.encode as ComponentEncoder)?.(type) ?? ''}/`
225+
/* c8 ignore next - Type encoder uses default PurlComponentEncoder, never returns null/undefined. */ let purlStr = `pkg:${(PurlComponent['type']?.['encode'] as ComponentEncoder)?.(type) ?? ''}/`
226226
if (namespace) {
227-
/* c8 ignore next - Namespace encoder always returns string, never null/undefined. */ purlStr = `${purlStr}${(PurlComponent.namespace?.encode as ComponentEncoder)?.(namespace) ?? ''}/`
227+
/* c8 ignore next - Namespace encoder always returns string, never null/undefined. */ purlStr = `${purlStr}${(PurlComponent['namespace']?.['encode'] as ComponentEncoder)?.(namespace) ?? ''}/`
228228
}
229-
/* c8 ignore next - Name encoder always returns string, never null/undefined. */ purlStr = `${purlStr}${(PurlComponent.name?.encode as ComponentEncoder)?.(name) ?? ''}`
229+
/* c8 ignore next - Name encoder always returns string, never null/undefined. */ purlStr = `${purlStr}${(PurlComponent['name']?.['encode'] as ComponentEncoder)?.(name) ?? ''}`
230230
if (version) {
231-
/* c8 ignore next - Version encoder always returns string, never null/undefined. */ purlStr = `${purlStr}@${(PurlComponent.version?.encode as ComponentEncoder)?.(version) ?? ''}`
231+
/* c8 ignore next - Version encoder always returns string, never null/undefined. */ purlStr = `${purlStr}@${(PurlComponent['version']?.['encode'] as ComponentEncoder)?.(version) ?? ''}`
232232
}
233233
if (qualifiers) {
234-
/* c8 ignore next - Qualifiers encoder always returns string, never null/undefined. */ purlStr = `${purlStr}?${(PurlComponent.qualifiers?.encode as ComponentEncoder)?.(qualifiers) ?? ''}`
234+
/* c8 ignore next - Qualifiers encoder always returns string, never null/undefined. */ purlStr = `${purlStr}?${(PurlComponent['qualifiers']?.['encode'] as ComponentEncoder)?.(qualifiers) ?? ''}`
235235
}
236236
if (subpath) {
237-
/* c8 ignore next - Subpath encoder always returns string, never null/undefined. */ purlStr = `${purlStr}#${(PurlComponent.subpath?.encode as ComponentEncoder)?.(subpath) ?? ''}`
237+
/* c8 ignore next - Subpath encoder always returns string, never null/undefined. */ purlStr = `${purlStr}#${(PurlComponent['subpath']?.['encode'] as ComponentEncoder)?.(subpath) ?? ''}`
238238
}
239239
return purlStr
240240
}
@@ -278,12 +278,12 @@ class PackageURL {
278278
// Create a safe object without prototype chain to prevent prototype pollution
279279
const safeObject: PackageURLObject = {
280280
__proto__: null,
281-
type: parsedRecord.type as string | undefined,
282-
namespace: parsedRecord.namespace as string | undefined,
283-
name: parsedRecord.name as string | undefined,
284-
version: parsedRecord.version as string | undefined,
285-
qualifiers: parsedRecord.qualifiers as Record<string, string> | undefined,
286-
subpath: parsedRecord.subpath as string | undefined,
281+
type: parsedRecord['type'] as string | undefined,
282+
namespace: parsedRecord['namespace'] as string | undefined,
283+
name: parsedRecord['name'] as string | undefined,
284+
version: parsedRecord['version'] as string | undefined,
285+
qualifiers: parsedRecord['qualifiers'] as Record<string, string> | undefined,
286+
subpath: parsedRecord['subpath'] as string | undefined,
287287
} as PackageURLObject
288288

289289
return PackageURL.fromObject(safeObject)
@@ -298,12 +298,12 @@ class PackageURL {
298298
}
299299
const typedObj = obj as Record<string, unknown>
300300
return new PackageURL(
301-
typedObj.type,
302-
typedObj.namespace,
303-
typedObj.name,
304-
typedObj.version,
305-
typedObj.qualifiers,
306-
typedObj.subpath,
301+
typedObj['type'],
302+
typedObj['namespace'],
303+
typedObj['name'],
304+
typedObj['version'],
305+
typedObj['qualifiers'],
306+
typedObj['subpath'],
307307
)
308308
}
309309

@@ -461,13 +461,15 @@ class PackageURL {
461461
const entries = search.split('&')
462462
for (let i = 0, { length } = entries; i < length; i += 1) {
463463
const pairs = entries[i]?.split('=')
464-
const value = decodePurlComponent('qualifiers', pairs.at(1) ?? '')
465-
// Use URLSearchParams#append to preserve plus signs
466-
// https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams#preserving_plus_signs
467-
/* c8 ignore next -- URLSearchParams.append has internal V8 branches we can't control. */ searchParams.append(
468-
pairs[0]!,
469-
value,
470-
)
464+
if (pairs) {
465+
const value = decodePurlComponent('qualifiers', pairs.at(1) ?? '')
466+
// Use URLSearchParams#append to preserve plus signs
467+
// https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams#preserving_plus_signs
468+
/* c8 ignore next -- URLSearchParams.append has internal V8 branches we can't control. */ searchParams.append(
469+
pairs[0]!,
470+
value,
471+
)
472+
}
471473
}
472474
// Split the remainder once from right on '?'
473475
rawQualifiers = searchParams

src/purl-type.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ const PurlType = createHelpersNamespaceObject(
224224
},
225225
// https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst#mlflow
226226
mlflow(purl: PurlObject) {
227-
if (purl.qualifiers?.repository_url?.includes('databricks')) {
227+
if (purl.qualifiers?.['repository_url']?.includes('databricks')) {
228228
lowerName(purl)
229229
}
230230
return purl
@@ -306,7 +306,7 @@ const PurlType = createHelpersNamespaceObject(
306306
// https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst#conan
307307
conan(purl: PurlObject, throws: boolean) {
308308
if (isNullishOrEmptyString(purl.namespace)) {
309-
if (purl.qualifiers?.channel) {
309+
if (purl.qualifiers?.['channel']) {
310310
if (throws) {
311311
throw new PurlError(
312312
'conan requires a "namespace" component when a "channel" qualifier is present',
@@ -542,7 +542,7 @@ const PurlType = createHelpersNamespaceObject(
542542
swid(purl: PurlObject, throws: boolean) {
543543
const { qualifiers } = purl
544544
// SWID requires a tag_id qualifier
545-
const tagId = qualifiers?.tag_id
545+
const tagId = qualifiers?.['tag_id']
546546
if (!tagId) {
547547
if (throws) {
548548
throw new PurlError('swid requires a "tag_id" qualifier')

src/validate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ function validateQualifiers(
170170
return false
171171
}
172172
const qualifiersObj = qualifiers as QualifiersObject | URLSearchParams
173-
const keysProperty = (qualifiersObj as QualifiersObject).keys
173+
const keysProperty = (qualifiersObj as QualifiersObject)['keys']
174174
// type-coverage:ignore-next-line -- TypeScript correctly infers this type through the ternary and cast
175175
const keysIterable: Iterable<string> =
176176
// URLSearchParams instances have a "keys" method that returns an iterator

0 commit comments

Comments
 (0)