@@ -19,7 +19,7 @@ use warnings;
1919# If you find tests are failing, please try adding names to tests to track
2020# down where the failure is, and supply your new names as a patch.
2121# (Just-in-time test naming)
22- plan tests => 510 + 6 * 2;
22+ plan tests => 512 + 6 * 2;
2323
2424# numerics
2525ok ((0xdead & 0xbeef) == 0x9ead);
725725 '',
726726 {}, "[perl #17844] access beyond end of block");
727727}
728+
729+ {
730+ # GH #9972 (previously [perl #70652])
731+
732+ my $warn = 0;
733+ use strict;
734+ use warnings;
735+ local $SIG {__WARN__} = sub { $warn ++ };
736+
737+ my $unicodestring = "\x{5454}\x{6655} ";
738+ my $normalstring = "0\36\4\13\200\0\31 V\3\0\320\225\342\26\365\4\0\240\r\2\3\0\242 _\2\1\0\2\1\0000\0\b\b\b\b\b\b\b\b ";
739+ my $iv = "\246\205\236\367 ]\257\304\276 ";
740+
741+ # First we need $1 to be unicode, otherwise the bug won't occur
742+ $unicodestring =~ m/(.)/;
743+
744+ my @t ;
745+
746+ # $1 is assigned but not yet unicode: UTF8-Flag ($1 )
747+ push @t , utf8::is_utf8 ($1 );
748+
749+ # After we copy $1 the Flag is on: UTF8-Flag ($1 )
750+ my $copy = $1 ;
751+ push @t , utf8::is_utf8 ($1 );
752+
753+ # Now we take 8 Bytes of a normal string with m/(.{8})/
754+ push @t , utf8::is_utf8 ($normalstring );
755+
756+ $normalstring =~ m/(.{8})/;
757+
758+ # The UTF-8 Flag of $1 is still on: UTF8-Flag ($1 )
759+ push @t , utf8::is_utf8 ($1 );
760+ # We have a second value called ($iv ) without an UTF-8 Flag : UTF8-Flag ($iv )
761+ push @t , utf8::is_utf8 ($iv );
762+
763+ # Now the UTF-8 Flag of $1 is off: UTF8-Flag ($1 )
764+ push @t , utf8::is_utf8 ($1 );
765+
766+ my $x = $1 ^ $iv ;
767+ # $1 is now not UTF-8 anymore UTF8-Flag ($1 )
768+ push @t , utf8::is_utf8 ($1 );
769+ # $x is now UTF-8: UTF8-Flag ($x )
770+ push @t , utf8::is_utf8 ($x );
771+ # $iv suddenly is also UTF-8: UTF8-Flag ($iv )
772+ push @t , utf8::is_utf8 ($iv );
773+
774+ ok(! $warn , "No warnings in this block");
775+ my $got = [@t ];
776+ my $exp = [1, 1, "", "", "", "", "", "", ""];
777+ ok( eq_array($got , $exp ), "GH 9972: no malformed UTF-8 character in bitwise xor");
778+ }
0 commit comments