Skip to content

Commit

Permalink
man: fix po4a's incorrect handling of \& in doblequotes
Browse files Browse the repository at this point in the history
Namely do `s/\\&"/\\(dq/` only until after we handle all the quotes that
might separate commands' arguments.

Closes: mquinson#445
Signed-off-by: Alexander Golubev <[email protected]>
  • Loading branch information
Fat-Zer committed Nov 12, 2024
1 parent 849b10e commit 3d9e892
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
12 changes: 6 additions & 6 deletions lib/Locale/Po4a/Man.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1674,25 +1674,25 @@ sub splitargs {
# anymore. Let's play safe.
$arguments =~ s/\\ /$nbs/g;
$arguments =~ s/^ +//;
$arguments =~ s/\\&"/\\(dq/g;
$arguments =~ s/^ *//;
while ( length $arguments ) {
my $a;
if ( $arguments =~ s/^"((?:[^"]|"")*)"(?!") *// ) {
my $a = $1;
$a = $1;
$a =~ s/""/"/g if defined $a;
push @args, $a;
} elsif ( $arguments =~ s/^"((?:[^"]|"")*) *$// ) {

# Unterminated quote, but this seems to be handled by removing
# the trailing spaces and closing the quotes.
my $a = $1;
$a = $1;
$a =~ s/""/"/g if defined $a;
push @args, $a;
} elsif ( $arguments =~ s/^([^ ]+) *// ) {
push @args, $1;
$a = $1;
} else {
die wrap_ref_mod( $ref, "po4a::man", dgettext( "po4a", "Cannot parse command arguments: %s" ), $arguments );
}
$a =~ s/\\&"/\\(dq/g if (defined $a);
push @args, $a;
}
if ( $debug{'splitargs'} ) {
print STDERR "ARGS=";
Expand Down
2 changes: 2 additions & 0 deletions t/fmt/man/quotes.man
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ should be equivalent to:

.BI "-help"""a "-h"a "-?"a "/?"

.\" Some shinenigans with \&, see https://github.com/mquinson/po4a/issues/445
.BI "[\& ]\&" \&"text\&" "[\& \&"" ]\&" "[\& \&"" ]\&
2 changes: 2 additions & 0 deletions t/fmt/man/quotes.norm
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ should be equivalent to:

\fB\-help"\fP\fIa\fP\fB\-h\fP\fIa\fP\fB\-?\fP\fIa\fP\fB/?\fP

.\" Some shinenigans with \&, see https://github.com/mquinson/po4a/issues/445
\fB[\& ]\&\fP\fI"text"\fP\fB[\& " ]\&\fP\fI[\& " ]\&\fP
8 changes: 7 additions & 1 deletion t/fmt/man/quotes.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2020-04-26 22:14+0200\n"
"POT-Creation-Date: 2024-11-12 14:36+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -83,3 +83,9 @@ msgstr "THIS ALSO:"
#: quotes.man:31 quotes.man:35
msgid "B<-help\">I<a>B<-h>I<a>B<-?>I<a>B</?>"
msgstr "B<-HELP\">I<1>B<-h>I<1>B<-?>I<1>B</?>"

#. Some shinenigans with \&, see https://github.com/mquinson/po4a/issues/445
#. type: Plain text
#: quotes.man:37
msgid "B<[\\& ]\\&>I<\"text\">B<[\\& \" ]\\&>I<[\\& \" ]\\&>"
msgstr "B<[\\& ]\\&>I<\"TEXT\">B<[\\& \" ]\\&>I<[\\& \" ]\\&>"
8 changes: 7 additions & 1 deletion t/fmt/man/quotes.pot
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2020-04-26 22:14+0200\n"
"POT-Creation-Date: 2024-11-12 14:36+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -83,3 +83,9 @@ msgstr ""
#: quotes.man:31 quotes.man:35
msgid "B<-help\">I<a>B<-h>I<a>B<-?>I<a>B</?>"
msgstr ""

#. Some shinenigans with \&, see https://github.com/mquinson/po4a/issues/445
#. type: Plain text
#: quotes.man:37
msgid "B<[\\& ]\\&>I<\"text\">B<[\\& \" ]\\&>I<[\\& \" ]\\&>"
msgstr ""
2 changes: 2 additions & 0 deletions t/fmt/man/quotes.trans
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ SHOULD BE EQUIVALENT TO:

\fB\-HELP"\fP\fI1\fP\fB\-h\fP\fI1\fP\fB\-?\fP\fI1\fP\fB/?\fP

.\" Some shinenigans with \&, see https://github.com/mquinson/po4a/issues/445
\fB[\& ]\&\fP\fI"TEXT"\fP\fB[\& " ]\&\fP\fI[\& " ]\&\fP

0 comments on commit 3d9e892

Please sign in to comment.