summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mg.c8
-rw-r--r--t/op/length.t18
2 files changed, 25 insertions, 1 deletions
diff --git a/mg.c b/mg.c
index 5a8c189e82..2e528ba538 100644
--- a/mg.c
+++ b/mg.c
@@ -185,7 +185,13 @@ Perl_mg_length(pTHX_ SV *sv)
}
}
- (void)SvPV(sv, len);
+ if (DO_UTF8(sv))
+ {
+ U8 *s = (U8*)SvPV(sv, len);
+ len = Perl_utf8_length(aTHX_ s, s + len);
+ }
+ else
+ (void)SvPV(sv, len);
return len;
}
diff --git a/t/op/length.t b/t/op/length.t
index c4445e3e48..3170beb156 100644
--- a/t/op/length.t
+++ b/t/op/length.t
@@ -115,3 +115,21 @@ print "ok 3\n";
print "ok 13\n";
$test++;
}
+
+# Now for Unicode with magical vtbls
+
+{
+ require Tie::Scalar;
+ my $a;
+ tie $a, 'Tie::StdScalar'; # makes $a magical
+ $a = "\x{263A}";
+
+ print "not " unless length($a) == 1;
+ print "ok 14\n";
+ $test++;
+
+ use bytes;
+ print "not " unless length($a) == 3;
+ print "ok 15\n";
+ $test++;
+}