]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
verify-examples.pl: fail verification on unescaped backslash
authorJay Satiro <raysatiro@yahoo.com>
Sat, 23 Dec 2023 21:45:53 +0000 (16:45 -0500)
committerJay Satiro <raysatiro@yahoo.com>
Thu, 28 Dec 2023 08:34:16 +0000 (03:34 -0500)
- Check that all backslashes in EXAMPLE are properly escaped.

eg manpage must always use `\\n` never `\n`.

This is because the manpage requires we always double blackslash to show
a single backslash. Prior to this change an erroneous single backslash
would pass through and compile even though it would not show correctly
in the manpage.

Co-authored-by: Daniel Stenberg
Ref: https://github.com/curl/curl/pull/12588

Closes https://github.com/curl/curl/pull/12589

.github/scripts/verify-examples.pl
.github/workflows/man-examples.yml

index 0b750711ea10e81ca204239361739a8c76d39336..377fe8340c4481bf7bc94933b282a42d3faad97d 100755 (executable)
@@ -26,6 +26,7 @@
 my @files = @ARGV;
 my $cfile = "test.c";
 my $check = "./scripts/checksrc.pl";
+my $error;
 
 if($files[0] eq "-h") {
     print "Usage: verify-synopsis [man pages]\n";
@@ -47,8 +48,9 @@ sub extract {
     my $syn = 0;
     my $l = 0;
     my $iline = 0;
-    open(F, "<$f");
-    open(O, ">$cfile");
+    my $fail = 0;
+    open(F, "<$f") or die "failed opening input file $f : $!";
+    open(O, ">$cfile") or die "failed opening output file $cfile : $!";
     print O "#include <curl/curl.h>\n";
     while(<F>) {
         $iline++;
@@ -68,6 +70,15 @@ sub extract {
             if(/^.fi/) {
                 last;
             }
+            if(/(?<!\\)(?:\\{2})*\\(?!\\)/) {
+                print STDERR
+                  "Error while processing file $f line $iline:\n$_" .
+                  "Error: Single backslashes \\ are not properly shown in " .
+                  "manpage EXAMPLE output unless they are escaped \\\\.\n";
+                $fail = 1;
+                $error = 1;
+                last;
+            }
             # two backslashes become one
             $_ =~ s/\\\\/\\/g;
             print O $_;
@@ -77,10 +88,9 @@ sub extract {
     close(F);
     close(O);
 
-    return $l;
+    return ($fail ? 0 : $l);
 }
 
-my $error;
 for my $m (@files) {
     print "Verify $m\n";
     my $out = extract($m);
index 080cb4c2da221564c21675ce7fd4ce1e2bd31cb2..640e3716cc236a3e577f94ffd03af29f5a913dd0 100644 (file)
@@ -12,12 +12,14 @@ on:
     paths:
       - 'docs/libcurl/curl_*.3'
       - 'docs/libcurl/opts/*.3'
+      - '.github/scripts/verify-examples.pl'
   pull_request:
     branches:
       - master
     paths:
       - 'docs/libcurl/curl_*.3'
       - 'docs/libcurl/opts/*.3'
+      - '.github/scripts/verify-examples.pl'
 
 jobs:
   verify: