Front page | perl.perl5.changes |
Postings from May 2008
Change 33951: Add index() tests for embedded nulls
From:
Dave Mitchell
Date:
May 30, 2008 14:30
Subject:
Change 33951: Add index() tests for embedded nulls
Change 33951 by davem@davem-pigeon on 2008/05/30 21:16:02
Add index() tests for embedded nulls
Subject: Re: [perl #53746] bug with index() matching beyond end of string when \0 bytes (00000000) are involved
From: Abigail <abigail@abigail.be>
Date: Tue, 6 May 2008 14:57:36 +0200
Message-Id: <20080506125736.GC17310@abigail.be>
Affected files ...
... //depot/perl/t/op/index.t#15 edit
Differences ...
==== //depot/perl/t/op/index.t#15 (xtext) ====
Index: perl/t/op/index.t
--- perl/t/op/index.t#14~32931~ 2008-01-09 14:42:04.000000000 -0800
+++ perl/t/op/index.t 2008-05-30 14:16:02.000000000 -0700
@@ -7,7 +7,7 @@
}
use strict;
-plan( tests => 69 );
+plan( tests => 111 );
run_tests() unless caller;
@@ -160,4 +160,43 @@
is(index($t, 'xyz'), 4, "0xfffffffd and utf8cache");
}
+
+# Tests for NUL characters.
+{
+ my @tests = (
+ ["", -1, -1, -1],
+ ["foo", -1, -1, -1],
+ ["\0", 0, -1, -1],
+ ["\0\0", 0, 0, -1],
+ ["\0\0\0", 0, 0, 0],
+ ["foo\0", 3, -1, -1],
+ ["foo\0foo\0\0", 3, 7, -1],
+ );
+ foreach my $l (1 .. 3) {
+ my $q = "\0" x $l;
+ my $i = 0;
+ foreach my $test (@tests) {
+ $i ++;
+ my $str = $$test [0];
+ my $res = $$test [$l];
+
+ {
+ local $::TODO = ($l == 3 && $i == 7 ? "Bug #53746" : "");
+ is (index ($str, $q), $res, "Find NUL character(s)");
+ }
+
+ #
+ # Bug #53746 shows a difference between variables and literals,
+ # so test literals as well.
+ #
+ my $test_str = qq {is (index ("$str", "$q"), $res, } .
+ qq {"Find NUL character(s)")};
+ $test_str =~ s/\0/\\0/g;
+
+ eval $test_str;
+ die $@ if $@;
+ }
+ }
+}
+
}
End of Patch.
-
Change 33951: Add index() tests for embedded nulls
by Dave Mitchell