mirror of
https://github.com/nodejs/node.git
synced 2025-05-17 18:26:24 +00:00

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>
25 lines
531 B
JavaScript
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
|