Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion lib/utils/replace-info.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
const { cleanUrl } = require('npm-registry-fetch')
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) {
url.password = replace
str = url.toString()
}
} catch {
// ignore errors
}

return str
.replace(tokenRegex, `npm_${replace}`)
.replace(guidRegex, `npm_${replace}`)
}

const isString = (v) => typeof v === 'string'

// split on \s|= similar to how nopt parses options
Expand Down