verify-examples.pl: fail verification on unescaped backslash

- 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
This commit is contained in:
Jay Satiro 2023-12-23 16:45:53 -05:00
parent e251e858b9
commit aa2c2ab837
2 changed files with 16 additions and 4 deletions

View File

@ -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);

View 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: