From: SADAHIRO Tomoyuki Date: Sat, 16 Jul 2005 22:05:13 +0000 (+0900) Subject: Re: [perl #36569] chop fails on decoded string with trailing nul X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ace7757b19d04728dc05eefe7b371b14d8ce29dd;p=p5sagit%2Fp5-mst-13.2.git Re: [perl #36569] chop fails on decoded string with trailing nul Message-Id: <20050716220041.2BDD.BQW10602@nifty.com> p4raw-id: //depot/perl@25158 --- diff --git a/doop.c b/doop.c index 27c3248..a36a04f 100644 --- a/doop.c +++ b/doop.c @@ -977,7 +977,7 @@ Perl_do_chop(pTHX_ register SV *astr, register SV *sv) s = send - 1; while (s > start && UTF8_IS_CONTINUATION(*s)) s--; - if (utf8_to_uvchr((U8*)s, 0)) { + if (is_utf8_string((U8*)s, send - s)) { sv_setpvn(astr, s, send - s); *s = '\0'; SvCUR_set(sv, s - start); diff --git a/t/op/chop.t b/t/op/chop.t index bacc439..a77ff30 100755 --- a/t/op/chop.t +++ b/t/op/chop.t @@ -6,7 +6,7 @@ BEGIN { require './test.pl'; } -plan tests => 133; +plan tests => 137; $_ = 'abc'; $c = do foo(); @@ -222,3 +222,13 @@ foreach my $start (@chars) { $b = chomp $a; is ($b, 2); } + +{ + # [perl #36569] chop fails on decoded string with trailing nul + my $asc = "perl\0"; + my $utf = "perl".pack('U',0); # marked as utf8 + is(chop($asc), "\0", "chopping ascii NUL"); + is(chop($utf), "\0", "chopping utf8 NUL"); + is($asc, "perl", "chopped ascii NUL"); + is($utf, "perl", "chopped utf8 NUL"); +}