Skip to content

cd2nroff: fix backslashes for 4-space indent lines - #22393

Closed
bagder wants to merge 5 commits into
masterfrom
bagder/cd2nroff-indent
Closed

cd2nroff: fix backslashes for 4-space indent lines#22393
bagder wants to merge 5 commits into
masterfrom
bagder/cd2nroff-indent

Conversation

@bagder

@bagder bagder commented Jul 25, 2026

Copy link
Copy Markdown
Member

They were previously only properly escaped for ~~~ quotes. Spotted for the CURLOPT_HTTPSIG_KEY man page.

They were previously only properly escaped for ~~~ quotes. Spotted for
the CURLOPT_HTTPSIG_KEY man page.
@bagder bagder added the script label Jul 25, 2026
Copilot AI review requested due to automatic review settings July 25, 2026 20:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread scripts/cd2nroff Outdated
escape leading apostrophes as well

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 25, 2026 20:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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";

Comment thread scripts/cd2nroff
Copilot AI review requested due to automatic review settings July 25, 2026 20:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copilot AI review requested due to automatic review settings July 25, 2026 20:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread scripts/cd2nroff
Copilot AI review requested due to automatic review settings July 25, 2026 20:40
@bagder
bagder marked this pull request as ready for review July 25, 2026 20:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@bagder bagder closed this in 163f0cb Jul 25, 2026
@bagder
bagder deleted the bagder/cd2nroff-indent branch July 25, 2026 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants