node/deps/npm/node_modules/npm-registry-fetch/lib/clean-url.js
npm team 2d84620f86
deps: upgrade npm to 8.6.0
PR-URL: https://github.com/nodejs/node/pull/42550
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Mestery <mestery@protonmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Tierney Cyren <hello@bnb.im>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
2022-04-09 12:56:30 +02:00

25 lines
531 B
JavaScript

const { URL } = require('url')
const replace = '***'
const tokenRegex = /\bnpm_[a-zA-Z0-9]{36}\b/g
const guidRegex = /\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/g
const cleanUrl = (str) => {
if (typeof str !== 'string' || !str) {
return str
}
try {
const url = new URL(str)
if (url.password) {
str = str.replace(url.password, replace)
}
} catch {}
return str
.replace(tokenRegex, `npm_${replace}`)
.replace(guidRegex, `npm_${replace}`)
}
module.exports = cleanUrl