diff options
author | Nicholas Clark <nick@ccl4.org> | 2005-01-11 19:10:20 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2005-01-11 19:10:20 +0000 |
commit | e609e5866582a76dcfe889f9b46e4909b2f0b543 (patch) | |
tree | 1598ae77df9042967af7d50d26903e5ae6e5212a /t/op | |
parent | 57f5baf2d376469520fedfc328fdf51d005eafe3 (diff) | |
download | perl-e609e5866582a76dcfe889f9b46e4909b2f0b543.tar.gz |
Fix bug 32294 - index()/rindex() ignore UTF8 flag
(for cases of mixed UTF8/bytes)
Test code based on bug report by John Gardiner Myers
p4raw-id: //depot/perl@23782
Diffstat (limited to 't/op')
-rwxr-xr-x | t/op/index.t | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/t/op/index.t b/t/op/index.t index 9e21e58e2b..d223265c4f 100755 --- a/t/op/index.t +++ b/t/op/index.t @@ -5,15 +5,16 @@ BEGIN { @INC = '../lib'; } +use strict; require './test.pl'; -plan( tests => 28 ); +plan( tests => 46 ); -$foo = 'Now is the time for all good men to come to the aid of their country.'; +my $foo = 'Now is the time for all good men to come to the aid of their country.'; -$first = substr($foo,0,index($foo,'the')); +my $first = substr($foo,0,index($foo,'the')); is($first, "Now is "); -$last = substr($foo,rindex($foo,'the'),100); +my $last = substr($foo,rindex($foo,'the'),100); is($last, "their country."); $last = substr($foo,index($foo,'Now'),2); @@ -69,3 +70,40 @@ is(rindex($a, "foo", ), 0); is($a, $b, q{[perl #22375] 'split'/'index' problem for utf8}); } } + +{ + my $search = "foo \xc9 bar"; + my $text = "a\xa3\xa3a $search $search quux"; + + my $text_utf8 = $text; + utf8::upgrade($text_utf8); + my $search_utf8 = $search; + utf8::upgrade($search_utf8); + + is (index($text, $search), 5); + is (rindex($text, $search), 18); + is (index($text, $search_utf8), 5); + is (rindex($text, $search_utf8), 18); + is (index($text_utf8, $search), 5); + is (rindex($text_utf8, $search), 18); + is (index($text_utf8, $search_utf8), 5); + is (rindex($text_utf8, $search_utf8), 18); + + my $text_octets = $text_utf8; + utf8::encode ($text_octets); + my $search_octets = $search_utf8; + utf8::encode ($search_octets); + + is (index($text_octets, $search_octets), 7, "index octets, octets") + or _diag ($text_octets, $search_octets); + is (rindex($text_octets, $search_octets), 21, "rindex octets, octets"); + is (index($text_octets, $search_utf8), -1); + is (rindex($text_octets, $search_utf8), -1); + is (index($text_utf8, $search_octets), -1); + is (rindex($text_utf8, $search_octets), -1); + + is (index($text_octets, $search), -1); + is (rindex($text_octets, $search), -1); + is (index($text, $search_octets), -1); + is (rindex($text, $search_octets), -1); +} |