1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

getpart.pm: make test definition section/part parser more robust

Test definition section parts which needed to include xml-lingo as contents
of that part required that the xml-blurb was written as a single line. Now the
xml-data inside the part can be written multiline making it more readable.

Tested with <client><file> part which is written to disk before <command> runs.
This commit is contained in:
Yang Tse 2012-06-20 20:13:07 +02:00
parent 066811592d
commit 07086c9487

View File

@ -5,7 +5,7 @@
# | (__| |_| | _ <| |___ # | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____| # \___|\___/|_| \_\_____|
# #
# Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. # Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
# #
# This software is licensed as described in the file COPYING, which # This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms # you should have received as part of this distribution. The terms
@ -88,21 +88,27 @@ sub getpart {
if(!$inside && ($_ =~ /^ *\<$section/)) { if(!$inside && ($_ =~ /^ *\<$section/)) {
$inside++; $inside++;
} }
elsif((1 ==$inside) && ($_ =~ /^ *\<$part[ \>]/)) { elsif(($inside >= 1) && ($_ =~ /^ *\<$part[ \>]/)) {
if($_ =~ /$part [^>]*base64=/) { if($inside > 1) {
# attempt to detect base64 encoded parts push @this, $_;
}
elsif($_ =~ /$part [^>]*base64=/) {
# attempt to detect our base64 encoded part
$base64=1; $base64=1;
} }
$inside++; $inside++;
} }
elsif((2 ==$inside) && ($_ =~ /^ *\<\/$part/)) { elsif(($inside >= 2) && ($_ =~ /^ *\<\/$part[ \>]/)) {
if($inside > 2) {
push @this, $_;
}
$inside--; $inside--;
} }
elsif((1==$inside) && ($_ =~ /^ *\<\/$section/)) { elsif(($inside >= 1) && ($_ =~ /^ *\<\/$section/)) {
if($trace) { if($trace && @this) {
print STDERR "*** getpart.pm: $section/$part returned data!\n"; print STDERR "*** getpart.pm: $section/$part returned data!\n";
} }
if(!@this && $warning) { if($warning && !@this) {
print STDERR "*** getpart.pm: $section/$part returned empty!\n"; print STDERR "*** getpart.pm: $section/$part returned empty!\n";
} }
if($base64) { if($base64) {
@ -114,14 +120,21 @@ sub getpart {
} }
return @this; return @this;
} }
elsif(2==$inside) { elsif($inside >= 2) {
push @this, $_; push @this, $_;
} }
} }
if($warning) { if($trace && @this) {
# section/part has data but end of section not detected,
# end of file implies end of section.
print STDERR "*** getpart.pm: $section/$part returned data!\n";
}
if($warning && !@this) {
# section/part does not exist or has no data without an end of
# section; end of file implies end of section.
print STDERR "*** getpart.pm: $section/$part returned empty!\n"; print STDERR "*** getpart.pm: $section/$part returned empty!\n";
} }
return @this; #empty! return @this; # empty when end of section detected
} }
sub partexists { sub partexists {