From a49f7c5361765431999b0f8146c4003b73957600 Mon Sep 17 00:00:00 2001 From: David Walker Date: Thu, 24 Mar 2022 02:10:21 -0700 Subject: [PATCH] fix: don't die if manNumberRegex doesn't match the glob (#4610) 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. --- lib/commands/help.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/commands/help.js b/lib/commands/help.js index 40f5ad9b30092..c390f1a5bb2dd 100644 --- a/lib/commands/help.js +++ b/lib/commands/help.js @@ -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) {