Skip to content

Commit

Permalink
fix: don't die if manNumberRegex doesn't match the glob (#4610)
Browse files Browse the repository at this point in the history
In certain edge cases, the glob could find files that manNumberRegex wouldn't match.

A possible solution would be to try to bring the two closer, but since globs and regexes are different syntaxes, the two will never be exactly the same.
It's always asking for bugs; better to just handle the issue directly.
  • Loading branch information
d0sboots authored Mar 24, 2022
1 parent 362831c commit a49f7c5
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/commands/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ class Help extends BaseCommand {
const f = `${manroot}/${manSearch}/?(npm-)${section}.[0-9]*`
let mans = await glob(f)
mans = mans.sort((a, b) => {
// Because of the glob we know the manNumberRegex will pass
const aManNumber = a.match(manNumberRegex)[1]
const bManNumber = b.match(manNumberRegex)[1]
// Because the glob is (subtly) different from manNumberRegex,
// we can't rely on it passing.
const aManNumber = (a.match(manNumberRegex) || Infinity)[1]
const bManNumber = (b.match(manNumberRegex) || Infinity)[1]

// man number sort first so that 1 aka commands are preferred
if (aManNumber !== bManNumber) {
Expand Down

0 comments on commit a49f7c5

Please # to comment.