Skip to content

Commit 14ec34b

Browse files
committed
Also document and unit-test the correct handling of UTF-8
1 parent 4ba9db7 commit 14ec34b

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

ext/XS-APItest/t/sv_streq.t

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
#!perl
22

3-
use Test::More tests => 7;
3+
use Test::More tests => 9;
44
use XS::APItest;
55

66
my $abc = "abc";
77
ok sv_streq($abc, "abc"), '$abc eq "abc"';
88
ok !sv_streq($abc, "def"), '$abc ne "def"';
99

10-
# consider also UTF-8 vs not
10+
{
11+
# U+00E9 = LATIN SMALL LETTER E WITH ACUTE
12+
# UTF-8: \xc3 \xa9
13+
my $cafe_LATIN1 = "caf\xe9";
14+
utf8::upgrade(my $cafe_UNICODE = "caf\x{00e9}");
15+
utf8::encode (my $cafe_UTF8 = "caf\x{00e9}");
16+
17+
# Latin-1 and Unicode strings should compare equal despite containing
18+
# different underlying bytes in the SvPV
19+
ok sv_streq($cafe_LATIN1, $cafe_UNICODE), 'sv_streq handles UTF8 strings';
20+
21+
# UTF-8 and Unicode strings should not compare equal, even though they
22+
# contain the same bytes in the SvPV
23+
ok !sv_streq($cafe_UTF8, $cafe_UNICODE), 'sv_streq takes UTF8ness into account';
24+
}
1125

1226
# GMAGIC
1327
"ABC" =~ m/(\w+)/;

sv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8191,7 +8191,7 @@ Perl_sv_eq_flags(pTHX_ SV *sv1, SV *sv2, const U32 flags)
81918191
Returns a boolean indicating whether the strings in the two SVs are
81928192
identical. If the flags argument has the C<SV_GMAGIC> bit set, it handles
81938193
get-magic too. Will coerce its args to strings if necessary. Treats
8194-
C<NULL> as undef.
8194+
C<NULL> as undef. Correctly handles the UTF8 flag.
81958195

81968196
If flags does not have the C<SV_SKIP_OVERLOAD> bit set, an attempt to use
81978197
C<eq> overloading will be made. If such overloading does not exist or the

0 commit comments

Comments
 (0)