Skip to content

Commit 423abb8

Browse files
committed
nginx-xml2pod: ensured <link> tags contents are parsed.
In recent nginx 1.15.8 documentation, the following XML document: <module name="Module ngx_stream_proxy_module" link="/en/docs/stream/ngx_stream_proxy_module.html"> <para> Enables terminating all sessions to a proxied server after it was removed from the group or marked as permanently unavailable. This can occur because of <link doc="ngx_stream_core_module.xml" id="resolver">re-resolve</link> or with the API <link doc="../http/ngx_http_api_module.xml" id="deleteStreamUpstreamServer"><literal>DELETE</literal></link> command. </para> </module> Would produce this output: Enables terminating all sessions to a proxied server after it was removed from the group or marked as permanently unavailable. This can occur because of L<re-resolve|ngx_stream_core_module> or with the API L<E<ltE<gt>literalE<gt>DELETEE<ltE<gt>E<sol>literalE<gt>|ngx_http_api_module> command. Thanks to this patch, the output is now: Enables terminating all sessions to a proxied server after it was removed from the group or marked as permanently unavailable. This can occur because of L<re-resolve|ngx_stream_core_module> or with the API L<C<DELETE>|ngx_http_api_module> command. Note that now, links can contain nested markup as well. --- We also modified the parsing of `\&\w+;` subjects (i.e. `&ldquo;`) to void a regression in the parsing of `welcome_nginx_facebook.pod`. The input: <link url="http://www.dcwg.org/fix/"> How to clean up or fix malicious software (&ldquo;malware&rdquo;) associated with DNS Changer </link> The (invalid) output without this change would be: L<How to clean up or fix malicious software (E<ldquo>malwareE<rdquo>) ... > Since we removed the `encode_pod()` call on the link's contents. The correct output is instead: L<How to clean up or fix malicious software (E<amp>ldquo;malwareE<amp>rdquo;) ...> So we forced the `encode_pod()` call when this subject is parsed _inside_ of a link's contents.
1 parent 631a147 commit 423abb8

File tree

1 file changed

+35
-21
lines changed

1 file changed

+35
-21
lines changed

bin/nginx-xml2pod

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ sub process_xml_file {
4141
my $directive;
4242
my @lists;
4343
my $syntax_block;
44+
my $link_attrs;
4445

4546
while (1) {
4647
#warn "scanner: ", pos_str($_);
@@ -98,36 +99,37 @@ sub process_xml_file {
9899
next;
99100
}
100101

101-
if (m{ \G < \s* link ( (?: \s+ \w+ \s* = \s* " [^"]* " )* ) >
102-
(.*?)
103-
< \s* / \s* link \s* > }gcxs)
104-
{
105-
my ($attrs, $label) = ($1, $2);
102+
if (m{ \G < \s* link ( (?: \s+ \w+ \s* = \s* " [^"]* " )* ) > }gcxs) {
103+
$link_attrs = parse_attrs($1);
106104

107-
$label = encode_pod(decode_xml($label));
108-
$label =~ s/^\s+|\s+$//gs;
105+
if (defined $link_attrs->{doc} || defined $link_attrs->{url}) {
106+
$pod .= "L<";
107+
}
108+
}
109109

110-
$attrs = parse_attrs($attrs);
110+
if (m{ \G < \s* / \s* link \s* > }gcxs) {
111+
if (!defined $link_attrs) {
112+
die "No attributes for link: $&";
113+
}
111114

112-
my $doc = $attrs->{doc};
113-
my $url = $attrs->{url};
114-
my $id = $attrs->{id};
115+
my $doc = $link_attrs->{doc};
116+
my $url = $link_attrs->{url};
117+
my $id = $link_attrs->{id};
115118

116119
if ($doc) {
117120
$doc =~ s{.*/}{};
118121
$doc =~ s/\.xml$//;
119-
$pod .= "L<$label|$doc>";
122+
$pod .= "|$doc>";
120123

121124
} elsif ($url) {
122-
$pod .= "L<$label|$url>";
123-
124-
} elsif ($id) {
125-
$pod .= "$label";
125+
$pod .= "|$url>";
126126

127-
} else {
127+
} elsif (!defined $id) {
128128
die "Bad link: $&";
129129
}
130130

131+
undef $link_attrs;
132+
131133
next;
132134
}
133135

@@ -496,9 +498,15 @@ _EOC_
496498
next;
497499
}
498500

499-
if (m{ \G \&(\w+); }gcxs) {
500-
my $entity = $1;
501-
$pod .= "E<$entity>";
501+
if (m{ \G (\&(\w+);) }gcxs) {
502+
if (!defined $link_attrs) {
503+
my $entity = $2;
504+
$pod .= "E<$entity>";
505+
506+
} else {
507+
$pod .= encode_pod(decode_xml($1));
508+
}
509+
502510
next;
503511
}
504512

@@ -509,7 +517,13 @@ _EOC_
509517
}
510518

511519
if (m{ \G ([^<&]+) }gcxs) {
512-
$pod .= encode_pod(decode_xml($1));
520+
my $txt = $1;
521+
522+
if ($link_attrs) {
523+
$txt =~ s/^\s+|\s+$//gs;
524+
}
525+
526+
$pod .= encode_pod(decode_xml($txt));
513527
next;
514528
}
515529

0 commit comments

Comments
 (0)