OpenSSL::Util::extract_pod_info(): Read the POD one paragraph at a time
authorRichard Levitte <levitte@openssl.org>
Fri, 13 Dec 2019 10:53:31 +0000 (11:53 +0100)
committerRichard Levitte <levitte@openssl.org>
Sat, 21 Dec 2019 21:53:54 +0000 (22:53 +0100)
POD files should always be treated this way

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/10621)

util/perl/OpenSSL/Util/Pod.pm

index b34161a04b48e2ae0b0e7c7fc25f33cf68274a76..9f63bf3f9690ae579e7e405128939ac689328d7c 100644 (file)
@@ -115,8 +115,18 @@ sub extract_pod_info {
     }
 
     my %podinfo = ( section => $defaults{section});
-    foreach (split /^/, $contents) {
-        s|\R$||;
+
+    # Regexp to split a text into paragraphs found at
+    # https://www.perlmonks.org/?node_id=584367
+    # Most of all, \G (continue at last match end) and /g (anchor
+    # this match for \G) are significant
+    foreach (map { /\G((?:(?!\n\n).)*\n+|.+\z)/sg } $contents) {
+        # Remove as many line endings as possible from the end of the paragraph
+        while (s|\R$||) {}
+
+        print STDERR "DEBUG: Paragraph:\n$_\n"
+            if $defaults{debug};
+
         # Stop reading when we have reached past the NAME section.
         last if (m|^=head1|
                  && defined $podinfo{lastsect}
@@ -148,7 +158,7 @@ sub extract_pod_info {
         print STDERR "DEBUG: Done reading $filename\n" if $defaults{debug};
     }
 
-    $podinfo{lastsecttext} =~ s| - .*$||;
+    $podinfo{lastsecttext} =~ s|\s+-\s+.*$||s;
 
     my @names =
         map { s/^\s+//g;        # Trim prefix blanks
@@ -157,6 +167,10 @@ sub extract_pod_info {
               $_ }
         split(m|,|, $podinfo{lastsecttext});
 
+    print STDERR
+        "DEBUG: Collected names are: ", join(', ', @names), "\n"
+        if $defaults{debug};
+
     return ( section => $podinfo{section},
              names => [ @names ],
              contents =>  $contents );