New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PATCH] Text::Balanced _succeed() fails on fillet #7049
Comments
From davidm.perl@math2.orgCreated by davidm.perl@math2.orgThe following patch corrects an error in Text::Balanced, in the _succeed() function, failed: substr outside of string at ../Text-Balanced-1.95/lib/Text/Balanced.pm line 70, The error was only noticed when performing an extract_quotelike in list context with Included also in this patch is a test case that fails with the original code. The ================== Inline Patch--- perl-5.8.3/lib/Text/Balanced/t/extqlk.t 2001-11-19 22:59:36.000000000 -0500
+++ perl-5.8.3-patched/lib/Text/Balanced/t/extqlk.t 2004-01-20 00:38:24.000000000 -0500
@@ -14,7 +14,7 @@
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)
-BEGIN { $| = 1; print "1..89\n"; }
+BEGIN { $| = 1; print "1..90\n"; }
END {print "not ok 1\n" unless $loaded;}
use Text::Balanced qw ( extract_quotelike );
$loaded = 1;
@@ -35,12 +35,15 @@
if ($str =~ s/\A# USING://) { $neg = 0; $cmd = $str; next; }
elsif ($str =~ /\A# TH[EI]SE? SHOULD FAIL/) { $neg = 1; next; }
elsif (!$str || $str =~ /\A#/) { $neg = 0; next }
+ my $setup_cmd = ($str =~ s/\A\{(.*)\}//) ? $1 : '';
+ my $tests = 'sl';
debug "\tUsing: $cmd\n";
debug "\t on: [$str]\n";
$str =~ s/\\n/\n/g;
my $orig = $str;
- my @res;
+ eval $setup_cmd if $setup_cmd ne '';
+ my @res;
eval qq{\@res = $cmd; };
debug "\t got:\n" . join "", map { $res[$_]=~s/\n/\\n/g; "\t\t\t$_: [$res[$_]]\n"} (0..$#res);
debug "\t left: " . (map { s/\n/\\n/g; "[$_]\n" } my $cpy1 = $str)[0];
@@ -50,16 +53,19 @@
print "\n";
$str = $orig;
- debug "\tUsing: scalar $cmd\n";
- debug "\t on: [$str]\n";
- $var = eval $cmd;
- print " ($@)" if $@ && $DEBUG;
- $var = "<undef>" unless defined $var;
- debug "\t scalar got: " . (map { s/\n/\\n/g; "[$_]\n" } $var)[0];
- debug "\t scalar left: " . (map { s/\n/\\n/g; "[$_]\n" } $str)[0];
- print "not " if ($str =~ '\A;')==$neg;
- print "ok ", $count++;
- print "\n";
+ eval $setup_cmd if $setup_cmd ne '';
+ if($tests =~ /s/) {
+ debug "\tUsing: scalar $cmd\n";
+ debug "\t on: [$str]\n";
+ $var = eval $cmd;
+ print " ($@)" if $@ && $DEBUG;
+ $var = "<undef>" unless defined $var;
+ debug "\t scalar got: " . (map { s/\n/\\n/g; "[$_]\n" } $var)[0];
+ debug "\t scalar left: " . (map { s/\n/\\n/g; "[$_]\n" } $str)[0];
+ print "not " if ($str =~ '\A;')==$neg;
+ print "ok ", $count++;
+ print "\n";
+ }
}
__DATA__
@@ -71,7 +77,6 @@
'b';
`cc`;
-
<<EOHERE; done();\nline1\nline2\nEOHERE\n; next;
<<EOHERE; done();\nline1\nline2\nEOHERE\n; next;
<<"EOHERE"; done()\nline1\nline2\nEOHERE\n and next
@@ -111,6 +116,9 @@
tr/x/y/;
y/x/y/;
+# fails on Text-Balanced-1.95
+{ $tests = 'l'; pos($str)=6 }012345<<E;\n\nE\n
+
# THESE SHOULD FAIL
s<$self->{pat}>{$self->{sub}}; # CAN'T HANDLE '>' in '->'
s-$self->{pap}-$self->{sub}-; # CAN'T HANDLE '-' in '->'
Inline Patchdiff -r -u perl-5.8.3/lib/Text/Balanced.pm perl-5.8.3-patched/lib/Text/Balanced.pm
--- perl-5.8.3/lib/Text/Balanced.pm 2003-07-04 10:33:00.000000000 -0400
+++ perl-5.8.3-patched/lib/Text/Balanced.pm 2004-01-19 23:50:58.000000000 -0500
@@ -58,6 +58,7 @@
my ($wantarray,$textref) = splice @_, 0, 2;
my ($extrapos, $extralen) = @_>18 ? splice(@_, -2, 2) : (0,0);
my ($startlen) = $_[5];
+ my $oppos = $_[6];
my $remainderpos = $_[2];
if ($wantarray)
{
@@ -67,7 +68,7 @@
push @res, substr($$textref,$from,$len);
}
if ($extralen) { # CORRECT FILLET
- my $extra = substr($res[0], $extrapos-$startlen, $extralen, "\n");
+ my $extra = substr($res[0], $extrapos-$oppos, $extralen, "\n");
$res[1] = "$extra$res[1]";
eval { substr($$textref,$remainderpos,0) = $extra;
substr($$textref,$extrapos,$extralen,"\n")} ;
================== Perl Info
|
From davidm.perl@math2.orgJust to cross-reference, this bug was also reported on CPAN by another -davidm
|
davidm.perl@math2.org - Status changed from 'new' to 'open' |
From @steve-m-hayNow fixed in bleadperl by the jumbo patch in ticket #25157. |
@steve-m-hay - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#25154 (status was 'resolved')
Searchable as RT25154$
The text was updated successfully, but these errors were encountered: