fix(man.lua): :Man ignores section of gzipped manpage #38235

Problem:
Under certain circumstances (e.g. gzipped manpages with mandoc),
:Man will not find the correct page because it does not process
multiple extensions correctly.
For example, with a file named strcpy.3p.gz, it will only check the .gz
part to try to check the section.
This leads to some pages being inaccessible because it will return the
page from the wrong section.

Solution:
Loop and try multiple extensions to try to find one which matches
the name of the section.
Also refactor the man.get_path function so that it can be tested.
This commit is contained in:
MP430
2026-03-10 21:26:40 +00:00
committed by GitHub
parent 145548a24a
commit b3324be0d8
2 changed files with 89 additions and 18 deletions

View File

@@ -259,6 +259,53 @@ describe(':Man', function()
os.remove(actual_file)
end)
-- if man -w returns multiple results, :Man should select the correct one.
it('matches correct manpage section and name', function()
-- mock the system function to return the results we want to test.
local function _test(results, name, sect)
return exec_lua(function()
local man = require 'man'
return man._match_manpage_path(results, name, sect)
end)
end
eq(
'/usr/share/man/man3/strcpy.3',
_test({
'/usr/share/man/man3/strcpy.3',
'/usr/share/man/man3/string.3',
}, 'strcpy')
)
eq(
'/usr/share/man/man3/strcpy.3',
_test({
'/usr/share/man/man3/string.3',
'/usr/share/man/man3/strcpy.3',
}, 'strcpy')
)
eq(
'/usr/share/man/man3/strcpy.3',
_test({
'/usr/share/man/man3p/strcpy.3p',
'/usr/share/man/man3/strcpy.3',
'/usr/share/man/man3/string.3',
'/usr/share/man/man7/string_copying.7',
}, 'strcpy', '3')
)
eq(
'/usr/share/man/man3/strcpy.3.gz',
_test({
'/usr/share/man/man3p/strcpy.3p.gz',
'/usr/share/man/man3/strcpy.3.gz',
'/usr/share/man/man3/string.3.gz',
'/usr/share/man/man7/string_copying.7.gz',
}, 'strcpy', '3')
)
end)
it('tries variants with spaces, underscores #22503', function()
eq({
{ vim.NIL, 'NAME WITH SPACES' },