Bug 272729 - space character in `man -K` option's regex
Summary: space character in `man -K` option's regex
Status: In Progress
Alias: None
Product: Documentation
Classification: Unclassified
Component: Manual Pages (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Ed Maste
URL: https://reviews.freebsd.org/D41282
Keywords:
Depends on:
Blocks:
 
Reported: 2023-07-26 08:31 UTC by Michael V
Modified: 2024-01-08 05:17 UTC (History)
3 users (show)

See Also:


Attachments
quote the regexp argument (1.31 KB, patch)
2023-07-26 09:23 UTC, Yuri Pankov
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael V 2023-07-26 08:31:44 UTC
When searching man page with `man -K` I need to escape space character with `\s`.

I looked into ma, egrep and re_format man page, this format is not documented anywhere.

extract from `man man`:

     -K regexp
             Does a full text search in all manual pages.  regexp is a regular
             expression as understood by “grep -E”.  This option requires
             mandoc(1).  This is a slow operation.

`man grep`:

     -E, --extended-regexp
             Interpret pattern as an extended regular expression (i.e., force
             grep to behave as egrep).


`man re_format`:

                                                          a ‘\’ followed by
     one of the characters ‘^.[$()|*+?{\’ (matching that character taken as an
     ordinary character), a ‘\’ followed by any other character‡ (matching
     that character taken as an ordinary character, as if the ‘\’ had not been
     present‡), 


I think the issue comes from the egrep regex format. But I have found nothing into its documentation.
Comment 1 Yuri Pankov freebsd_committer freebsd_triage 2023-07-26 09:23:16 UTC
Created attachment 243625 [details]
quote the regexp argument

This rather seems to be a problem with quoting the regexp argument.  We should also just quit after processing -K option (according to synopsis).
Comment 2 Michael V 2023-07-26 11:41:53 UTC
To be totally clear. I think there are 2 issues here:

1. The behavior of -K regex.
This does work:

  man -K "BIOS\sextension"

this doesn't:

  man -K "BIOS extension"


2. the fact that '\s' is not documented in man page and contradict re_format man page.
Comment 3 Ed Maste freebsd_committer freebsd_triage 2023-08-01 18:03:54 UTC
(In reply to Yuri Pankov from comment #1)
The only part needed should be:
grep -E ${gflags} "${manfile}" -e "${re}"

Spaces are preserved in variable assignment, e.g. in re=${1}

Proposed change in https://reviews.freebsd.org/D41282
Comment 4 commit-hook freebsd_committer freebsd_triage 2023-08-02 20:48:50 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=8a5c836b51ce29fb22e0692c03fbc1e405c6522f

commit 8a5c836b51ce29fb22e0692c03fbc1e405c6522f
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2023-08-01 18:00:48 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2023-08-02 20:46:57 +0000

    man: fix `man -K` search

    Quote re arg to grep in case it has spaces, and quote [:blank:] tr arg
    to avoid the shell interpreting [].

    PR:             272729
    Reviewed by:    Mina Galić <freebsd@igalic.co>
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D41282

 usr.bin/man/man.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Comment 5 Mark Linimon freebsd_committer freebsd_triage 2024-01-08 05:17:56 UTC
^Triage: assign to committer and ask if possible interest in MFC.