From: alexander_bluhm@genua.de <alexander_bluhm@genua.de>
Date: Fri, 17 Nov 2006 09:31:48 +0000 (-0800)
Subject: [perl #40921] shellwords.pl cannot handle trailing backslash
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9983eac85a219459e624c0c0778fb334b52e6ead;p=p5sagit%2Fp5-mst-13.2.git

[perl #40921] shellwords.pl cannot handle trailing backslash
From: alexander_bluhm@genua.de (via RT) <perlbug-followup@perl.org>
Message-ID: <rt-3.5.HEAD-32013-1163784707-1469.40921-75-0@perl.org>

(and convert the example to a test)

p4raw-id: //depot/perl@29316
---

diff --git a/lib/Text/ParseWords.pm b/lib/Text/ParseWords.pm
index 1411986..78f7b24 100644
--- a/lib/Text/ParseWords.pm
+++ b/lib/Text/ParseWords.pm
@@ -133,7 +133,7 @@ sub old_shellwords {
 		Carp::carp("Unmatched single quote: $_");
 		return();
 	    }
-	    elsif (s/\A\\(.)//s) {
+	    elsif (s/\A\\(.?)//s) {
 		$snippet = $1;
 	    }
 	    elsif (s/\A([^\s\\'"]+)//) {
diff --git a/lib/Text/ParseWords.t b/lib/Text/ParseWords.t
index a0a6e51..57bdbd0 100755
--- a/lib/Text/ParseWords.t
+++ b/lib/Text/ParseWords.t
@@ -7,7 +7,7 @@ BEGIN {
 
 use warnings;
 use Text::ParseWords;
-use Test::More tests => 26;
+use Test::More tests => 27;
 
 @words = shellwords(qq(foo "bar quiz" zoo));
 is($words[0], 'foo');
@@ -117,3 +117,9 @@ is($result, "");
 # from parse_line, so it's behavior is more like /bin/sh
 $result = join('|', shellwords(" aa \\  \\ bb ", " \\  ", "cc dd ee\\ "));
 is($result, "aa| | bb| |cc|dd|ee ");
+
+$SIG{ALRM} = sub {die "Timeout!"};
+alarm(3);
+@words = Text::ParseWords::old_shellwords("foo\\");
+is(@words, 1);
+alarm(0);