summaryrefslogtreecommitdiff
path: root/lib/Text
diff options
context:
space:
mode:
authorMarcus Holland-Moritz <mhx-perl@gmx.net>2004-06-24 19:51:06 +0000
committerMarcus Holland-Moritz <mhx-perl@gmx.net>2004-06-24 19:51:06 +0000
commita8c6c617075a77facc3560cfdaa8948a894f9baf (patch)
treebd8981bf57df618e614cf15be8278f5fe7fc40df /lib/Text
parent7832186692f2b5bb0ae5b8a911736baf4ab3ff87 (diff)
downloadperl-a8c6c617075a77facc3560cfdaa8948a894f9baf.tar.gz
Fix for: [perl #30442] Text::ParseWords does not handle backslashed newline inside quoted text
Use the suggested regex fix, plus some tests. p4raw-id: //depot/perl@22992
Diffstat (limited to 'lib/Text')
-rw-r--r--lib/Text/ParseWords.pm10
-rwxr-xr-xlib/Text/ParseWords.t13
2 files changed, 17 insertions, 6 deletions
diff --git a/lib/Text/ParseWords.pm b/lib/Text/ParseWords.pm
index e758bc6ba2..fbc0ee038f 100644
--- a/lib/Text/ParseWords.pm
+++ b/lib/Text/ParseWords.pm
@@ -1,7 +1,7 @@
package Text::ParseWords;
use vars qw($VERSION @ISA @EXPORT $PERL_SINGLE_QUOTE);
-$VERSION = "3.21";
+$VERSION = "3.22";
require 5.000;
@@ -59,11 +59,11 @@ sub parse_line {
($quote, $quoted, undef, $unquoted, $delim, undef) =
$line =~ m/^(["']) # a $quote
- ((?:\\.|(?!\1)[^\\])*) # and $quoted text
+ ((?:\\[\000-\377]|(?!\1)[^\\])*) # and $quoted text
\1 # followed by the same quote
([\000-\377]*) # and the rest
| # --OR--
- ^((?:\\.|[^\\"'])*?) # an $unquoted text
+ ^((?:\\[\000-\377]|[^\\"'])*?) # an $unquoted text
(\Z(?!\n)|(?-x:$delimiter)|(?!^)(?=["']))
# plus EOL, delimiter, or quote
([\000-\377]*) # the rest
@@ -76,9 +76,9 @@ sub parse_line {
$quoted = "$quote$quoted$quote";
}
else {
- $unquoted =~ s/\\(.)/$1/g;
+ $unquoted =~ s/\\([\000-\377])/$1/g;
if (defined $quote) {
- $quoted =~ s/\\(.)/$1/g if ($quote eq '"');
+ $quoted =~ s/\\([\000-\377])/$1/g if ($quote eq '"');
$quoted =~ s/\\([\\'])/$1/g if ( $PERL_SINGLE_QUOTE && $quote eq "'");
}
}
diff --git a/lib/Text/ParseWords.t b/lib/Text/ParseWords.t
index 261d81f3a4..ef0e562e32 100755
--- a/lib/Text/ParseWords.t
+++ b/lib/Text/ParseWords.t
@@ -8,7 +8,7 @@ BEGIN {
use warnings;
use Text::ParseWords;
-print "1..18\n";
+print "1..20\n";
@words = shellwords(qq(foo "bar quiz" zoo));
print "not " if $words[0] ne 'foo';
@@ -108,3 +108,14 @@ print "ok 17\n";
@words = quotewords(' ', 1, '4 3 2 1 0');
print "not " unless join(";", @words) eq qq(4;3;2;1;0);
print "ok 18\n";
+
+# [perl #30442] Text::ParseWords does not handle backslashed newline inside quoted text
+$string = qq{"field1" "field2\\\nstill field2" "field3"};
+
+$result = join('|', parse_line("\t", 1, $string));
+print "not " unless $result eq qq{"field1"|"field2\\\nstill field2"|"field3"};
+print "ok 19\n";
+
+$result = join('|', parse_line("\t", 0, $string));
+print "not " unless $result eq "field1|field2\nstill field2|field3";
+print "ok 20\n";