From 07086c9487540d792f84d6d84687a6c986f9b138 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Wed, 20 Jun 2012 20:13:07 +0200 Subject: [PATCH] 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 part which is written to disk before runs. --- tests/getpart.pm | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/tests/getpart.pm b/tests/getpart.pm index d9510dd20..3e9c5a4d5 100644 --- a/tests/getpart.pm +++ b/tests/getpart.pm @@ -5,7 +5,7 @@ # | (__| |_| | _ <| |___ # \___|\___/|_| \_\_____| # -# Copyright (C) 1998 - 2011, Daniel Stenberg, , et al. +# Copyright (C) 1998 - 2012, Daniel Stenberg, , et al. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms @@ -88,21 +88,27 @@ sub getpart { if(!$inside && ($_ =~ /^ *\<$section/)) { $inside++; } - elsif((1 ==$inside) && ($_ =~ /^ *\<$part[ \>]/)) { - if($_ =~ /$part [^>]*base64=/) { - # attempt to detect base64 encoded parts + elsif(($inside >= 1) && ($_ =~ /^ *\<$part[ \>]/)) { + if($inside > 1) { + push @this, $_; + } + elsif($_ =~ /$part [^>]*base64=/) { + # attempt to detect our base64 encoded part $base64=1; } $inside++; } - elsif((2 ==$inside) && ($_ =~ /^ *\<\/$part/)) { + elsif(($inside >= 2) && ($_ =~ /^ *\<\/$part[ \>]/)) { + if($inside > 2) { + push @this, $_; + } $inside--; } - elsif((1==$inside) && ($_ =~ /^ *\<\/$section/)) { - if($trace) { + elsif(($inside >= 1) && ($_ =~ /^ *\<\/$section/)) { + if($trace && @this) { print STDERR "*** getpart.pm: $section/$part returned data!\n"; } - if(!@this && $warning) { + if($warning && !@this) { print STDERR "*** getpart.pm: $section/$part returned empty!\n"; } if($base64) { @@ -114,14 +120,21 @@ sub getpart { } return @this; } - elsif(2==$inside) { + elsif($inside >= 2) { 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"; } - return @this; #empty! + return @this; # empty when end of section detected } sub partexists {