cd2nroff: fix backslashes for 4-space indent lines - #22393
Conversation
They were previously only properly escaped for ~~~ quotes. Spotted for the CURLOPT_HTTPSIG_KEY man page.
There was a problem hiding this comment.
Pull request overview
This PR adjusts scripts/cd2nroff’s handling of roff-unsafe characters in quoted/code-block output, with the goal of correctly escaping backslashes (notably for 4-space-indented blocks) when generating manpages.
Changes:
- Introduces a
quoted()helper to centralize escaping for quote/code-block lines. - Applies
quoted()during quote processing, including for lines inside 4-space-indented quote blocks. - Replaces the inlined escaping logic in the quote-path with the helper.
Comments suppressed due to low confidence (1)
scripts/cd2nroff:407
- The 4-space indented quote path still leaves the first indented line unescaped: when the quote starts, the code pushes ".nf\n$1\n" directly (around the quote-start branch near lines ~519-525), bypassing quoted(). This means backslashes / leading roff control characters can still break rendering on the first line of each indented block.
# remove the indentation
if($d =~ /^ (.*)/) {
$d = quoted($1);
push @desc, "$d\n";
next;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
escape leading apostrophes as well Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
scripts/cd2nroff:403
- The new quoted() call fixes escaping for subsequent lines within a 4-space indented block, but the first line of that block is still emitted unescaped when the quote starts (see the /^ (.*)/ branch that sets $quote = 4 and pushes ".nf\n$1\n"). That means a leading '.'/' or backslashes on the first indented line are still problematic.
if($quote == 4) {
# remove the indentation
if($d =~ /^ (.*)/) {
$d = quoted($1);
push @desc, "$d\n";
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
scripts/cd2nroff:209
- The new quoted() helper no longer escapes backslashes for .nf quote/code blocks. In roff, a single backslash starts an escape sequence, so code examples like \r\n, " (comment), etc. will be interpreted and rendered incorrectly. This also means the intended fix for 4-space indented blocks doesn’t actually address backslash escaping.
quoted() should first double existing backslashes, then (separately) prefix lines that start with '.' or ''' with & so the inserted escape is not itself doubled.
sub quoted {
my ($d) = @_;
# in verbatim/quoted blocks, make backslashes literal
$d =~ s/\\/\\\\/g;
# lines starting with a period or apostrophe need it escaped
scripts/cd2nroff:410
- When ending a 4-space indented quote/code block, the first non-indented line is currently dropped because the loop
nexts after emitting ".fi". For indented blocks, there is no delimiter line to intentionally consume, so this loses real content (the line that ends the block should be processed normally).
push @desc, "$d\n";
next;
}
else {
# end of quote
They were previously only properly escaped for ~~~ quotes. Spotted for the CURLOPT_HTTPSIG_KEY man page.