diff options
author | Karl Williamson <khw@khw-desktop.(none)> | 2010-05-11 10:57:41 -0600 |
---|---|---|
committer | Rafael Garcia-Suarez <rgs@consttype.org> | 2010-05-17 09:51:56 +0200 |
commit | 3e462cdc2087ddf90984010fabd80c30db92bfa0 (patch) | |
tree | ab2329f812aa22c7ea9553d4d2d8299aadc7327b /t | |
parent | 618c9ef5ca707d1f047f20c323241c7349ab59c9 (diff) | |
download | perl-3e462cdc2087ddf90984010fabd80c30db92bfa0.tar.gz |
[perl #41530] s/non-utf8/is-utf8/ fails.
When the replacement is in utf8, there was failure to upgrade the result
when the source and the pattern weren't in utf8. This simply checks
that when there is a match that will lead to the replacement being done.
It then does the upgrade. If this led to changes in the source, we redo
the match because pointers to saved buffers could have changed. There
may be other cases where we don't need to redo the match, but I don't
know the code well-enough to easily figure it out.
Diffstat (limited to 't')
-rw-r--r-- | t/re/subst.t | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/t/re/subst.t b/t/re/subst.t index 042f67acc7..82c4a6ff8b 100644 --- a/t/re/subst.t +++ b/t/re/subst.t @@ -7,7 +7,7 @@ BEGIN { } require './test.pl'; -plan( tests => 143 ); +plan( tests => 149 ); $x = 'foo'; $_ = "x"; @@ -614,3 +614,23 @@ fresh_perl_is( '$_="abcef"; s/bc|(.)\G(.)/$1 ? "[$1-$2]" : "XX"/ge; print' => 'a 'bug: $var =~ s/$qr//e calling get-magic on $_ as well as $var', ); } + +{ # Bug #41530; replacing non-utf8 with a utf8 causes problems + my $string = "a\x{a0}a"; + my $sub_string = $string; + ok(! utf8::is_utf8($sub_string), "Verify that string isn't initially utf8"); + $sub_string =~ s/a/\x{100}/g; + ok(utf8::is_utf8($sub_string), + 'Verify replace of non-utf8 with utf8 upgrades to utf8'); + is($sub_string, "\x{100}\x{A0}\x{100}", + 'Verify #41530 fixed: replace of non-utf8 with utf8'); + + my $non_sub_string = $string; + ok(! utf8::is_utf8($non_sub_string), + "Verify that string isn't initially utf8"); + $non_sub_string =~ s/b/\x{100}/g; + ok(! utf8::is_utf8($non_sub_string), + "Verify that failed substitute doesn't change string's utf8ness"); + is($non_sub_string, $string, + "Verify that failed substitute doesn't change string"); +} |