Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix manNumberRegex in help.js #2949

Merged
merged 1 commit into from Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/help.js
Expand Up @@ -9,7 +9,7 @@ const BaseCommand = require('./base-command.js')
// Strips out the number from foo.7 or foo.7. or foo.7.tgz
// We don't currently compress our man pages but if we ever did this would
// seemlessly continue supporting it
const manNumberRegex = /\.(\d+)(\..*)?$/
const manNumberRegex = /\.(\d+)(\.[^/\\]*)?$/

class Help extends BaseCommand {
/* istanbul ignore next - see test/lib/load-all-commands.js */
Expand Down
23 changes: 23 additions & 0 deletions test/lib/help.js
Expand Up @@ -340,3 +340,26 @@ test('npm help - man viewer propagates errors', t => {
t.end()
})
})

test('npm help with complex installation path finds proper help file', t => {
npmConfig.viewer = 'browser'
globResult = [
'C:/Program Files/node-v14.15.5-win-x64/node_modules/npm/man/man1/npm-install.1',
// glob always returns forward slashes, even on Windows
]

t.teardown(() => {
npmConfig.viewer = undefined
globResult = globDefaults
spawnBin = null
spawnArgs = null
})

return help.exec(['1', 'install'], (err) => {
if (err)
throw err

t.match(openUrlArg, /commands(\/|\\)npm-install.html$/, 'attempts to open the correct url')
t.end()
})
})