diff --git a/lib/util/purl.js b/lib/util/purl.js index bc89cc33271bafdd2f62962d81c497a41da9d2a3..f3f3805f9069fbf190da5b4a2b21d73f5f7fd674 100644 --- a/lib/util/purl.js +++ b/lib/util/purl.js @@ -10,50 +10,50 @@ function parse(input) { if (!input.startsWith(scheme)) { return null; } - const res = {}; + const purl = {}; let remaining = input.substring(scheme.length); let parts = remaining.split('#'); if (parts.length > 1) { - [remaining, res.subpath] = parts; + [remaining, purl.subpath] = parts; } parts = remaining.split('?'); if (parts.length > 1) { - [remaining, res.qualifiers] = parts; + [remaining, purl.qualifiers] = parts; } parts = remaining.split('@'); if (parts.length > 1) { - [remaining, res.version] = parts; + [remaining, purl.version] = parts; } parts = remaining.split('/'); - [res.datasource, ...remaining] = parts; + [purl.datasource, ...remaining] = parts; if (remaining.length === 1) { - [res.name] = remaining; - res.lookupName = res.name; + [purl.name] = remaining; + purl.lookupName = purl.name; } else { - res.name = remaining.pop(); - res.namespace = remaining.join('/').replace('%40', '@'); - res.lookupName = res.namespace + '/' + res.name; + purl.name = remaining.pop(); + purl.namespace = remaining.join('/').replace('%40', '@'); + purl.lookupName = purl.namespace + '/' + purl.name; } - if (res.qualifiers) { - const allQualifiers = res.qualifiers.split('&'); - res.qualifiers = {}; + if (purl.qualifiers) { + const allQualifiers = purl.qualifiers.split('&'); + purl.qualifiers = {}; allQualifiers.forEach(qualifier => { const [key, val] = qualifier.split('='); - res.qualifiers[key] = val; + purl.qualifiers[key] = val; }); - if (res.qualifiers.repository_url) { - res.registryUrls = res.qualifiers.repository_url.split(','); - delete res.qualifiers.repository_url; + if (purl.qualifiers.repository_url) { + purl.registryUrls = purl.qualifiers.repository_url.split(','); + delete purl.qualifiers.repository_url; } } else { - res.qualifiers = {}; + purl.qualifiers = {}; } - if (res.subpath) { - res.lookupType = res.subpath; - delete res.subpath; + if (purl.subpath) { + purl.lookupType = purl.subpath; + delete purl.subpath; } - delete res.namespace; - delete res.name; - delete res.version; // we don't use it - return res; + delete purl.namespace; + delete purl.name; + delete purl.version; // we don't use it + return purl; }