Skip to content

Commit 487731c

Browse files
committed
fix(logging): sanitize logged argv
Wraps logged process.argv in `replaceInfo` Removes logged process.argv from EJSONPARSE warning for top level package.json merge conflicts. It is currently not even working (er.file is not being populated by the parsing library right now), and process.argv contains fullly resolved paths which isn't very nice looking. The user knows what they typed, it's enough to tell them to retry. PR-URL: #3658 Credit: @wraithgar Close: #3658 Reviewed-by: @nlf
1 parent 7a58264 commit 487731c

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

lib/cli.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ module.exports = async (process) => {
2727
if (process.argv[1][process.argv[1].length - 1] === 'g')
2828
process.argv.splice(1, 1, 'npm', '-g')
2929

30-
log.verbose('cli', process.argv)
30+
const replaceInfo = require('../lib/utils/replace-info.js')
31+
log.verbose('cli', replaceInfo(process.argv))
3132

3233
log.info('using', 'npm@%s', npm.version)
3334
log.info('using', 'node@%s', process.version)

lib/utils/error-message.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ module.exports = (er, npm) => {
109109
[
110110
'Merge conflict detected in your package.json.',
111111
'',
112-
'Please resolve the package.json conflict and retry the command:',
113-
'',
114-
`$ ${process.argv.join(' ')}`,
112+
'Please resolve the package.json conflict and retry.',
115113
].join('\n'),
116114
])
117115
break

tap-snapshots/test/lib/utils/error-message.js.test.cjs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,9 +1537,7 @@ Object {
15371537
String(
15381538
Merge conflict detected in your package.json.
15391539
1540-
Please resolve the package.json conflict and retry the command:
1541-
1542-
$ arg v
1540+
Please resolve the package.json conflict and retry.
15431541
),
15441542
],
15451543
],

test/lib/cli.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,32 @@ t.test('calling with --versions calls npm version with no args', async t => {
104104
t.strictSame(exitHandlerCalled, [])
105105
})
106106

107+
t.test('logged argv is sanitized', async t => {
108+
const proc = processMock({
109+
argv: ['node', 'npm', 'testcommand', 'https://username:[email protected]/test_url_with_a_password'],
110+
})
111+
const { npm } = mockNpm(t)
112+
const cli = cliMock(npm)
113+
114+
npm.commands.testcommand = (args, cb) => {
115+
cb()
116+
}
117+
118+
await cli(proc)
119+
t.equal(proc.title, 'npm')
120+
t.strictSame(logs, [
121+
'pause',
122+
['verbose', 'cli', [
123+
'node',
124+
'npm',
125+
'testcommand',
126+
'https://username:***@npmjs.org/test_url_with_a_password',
127+
]],
128+
['info', 'using', 'npm@%s', npm.version],
129+
['info', 'using', 'node@%s', process.version],
130+
])
131+
})
132+
107133
t.test('print usage if no params provided', async t => {
108134
const proc = processMock({
109135
argv: ['node', 'npm'],

0 commit comments

Comments
 (0)