Skip to content

Commit 21d98cf

Browse files
committed
man: escape all hyphens in flag names
Apparently, if we don't do this, some roff renderers with use a special Unicode hyphen. That in turn makes searching a man page not work as one would expect. Fixes #3140
1 parent 43b5ebf commit 21d98cf

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Bug fixes:
2727
Fix a bug where ripgrep would mishandle globs that ended with a `.`.
2828
* [BUG #3108](https://github.com/BurntSushi/ripgrep/issues/3108):
2929
Fix a bug where `-q --files-without-match` inverted the exit code.
30+
* [BUG #3140](https://github.com/BurntSushi/ripgrep/issues/3140):
31+
Ensure hyphens in flag names are escaped in the roff text for the man page.
3032

3133
Feature enhancements:
3234

‎crates/core/flags/defs.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5576,9 +5576,9 @@ don't need preprocessing. For example, given the following shell script,
55765576
pdftotext "$1" -
55775577
.EE
55785578
.sp
5579-
then it is possible to use \fB\-\-pre\fP \fIpre-pdftotext\fP \fB--pre-glob
5580-
'\fP\fI*.pdf\fP\fB'\fP to make it so ripgrep only executes the
5581-
\fIpre-pdftotext\fP command on files with a \fI.pdf\fP extension.
5579+
then it is possible to use \fB\-\-pre\fP \fIpre-pdftotext\fP
5580+
\fB\-\-pre\-glob\fP '\fI*.pdf\fP' to make it so ripgrep only executes
5581+
the \fIpre-pdftotext\fP command on files with a \fI.pdf\fP extension.
55825582
.sp
55835583
Multiple \flag{pre-glob} flags may be used. Globbing rules match
55845584
\fBgitignore\fP globs. Precede a glob with a \fB!\fP to exclude it.

‎crates/core/flags/doc/man.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn generate_flag(flag: &'static dyn Flag, out: &mut String) {
5353
write!(out, r", ");
5454
}
5555

56-
let name = flag.name_long();
56+
let name = flag.name_long().replace("-", r"\-");
5757
write!(out, r"\fB\-\-{name}\fP");
5858
if let Some(var) = flag.doc_variable() {
5959
write!(out, r"=\fI{var}\fP");
@@ -71,7 +71,7 @@ fn generate_flag(flag: &'static dyn Flag, out: &mut String) {
7171
if let Some(name) = flag.name_short() {
7272
write!(out, r"\-{}/", char::from(name));
7373
}
74-
write!(out, r"\-\-{}", flag.name_long());
74+
write!(out, r"\-\-{}", flag.name_long().replace("-", r"\-"));
7575
out.push_str(r"\fP");
7676
});
7777
// Convert \flag-negate{foo} into something nicer.

0 commit comments

Comments
 (0)