From: Gurusamy Sarathy Date: Sun, 7 May 2000 16:05:16 +0000 (+0000) Subject: reverse() and quotemeta() weren't preserving utf8-ness; add tests X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3aa33fe55ba20233f560f0c549294d8e83806012;p=p5sagit%2Fp5-mst-13.2.git reverse() and quotemeta() weren't preserving utf8-ness; add tests p4raw-id: //depot/perl@6087 --- diff --git a/pp.c b/pp.c index 03ced37..e148197 100644 --- a/pp.c +++ b/pp.c @@ -1078,7 +1078,7 @@ PP(pp_repeat) else { /* Note: mark already snarfed by pp_list */ SV *tmpstr = POPs; STRLEN len; - bool isutf = SvUTF8(tmpstr) ? TRUE : FALSE; + bool isutf = DO_UTF8(tmpstr); SvSetSV(TARG, tmpstr); SvPV_force(TARG, len); @@ -2212,7 +2212,6 @@ PP(pp_chr) tmps = SvPVX(TARG); *tmps++ = value; *tmps = '\0'; - SvUTF8_off(TARG); /* decontaminate */ (void)SvPOK_only(TARG); XPUSHs(TARG); RETURN; @@ -2545,7 +2544,7 @@ PP(pp_quotemeta) } *d = '\0'; SvCUR_set(TARG, d - SvPVX(TARG)); - (void)SvPOK_only(TARG); + (void)SvPOK_only_UTF8(TARG); } else sv_setpvn(TARG, s, len); @@ -3234,7 +3233,7 @@ PP(pp_reverse) *up++ = *down; *down-- = tmp; } - (void)SvPOK_only(TARG); + (void)SvPOK_only_UTF8(TARG); } SP = MARK + 1; SETTARG; diff --git a/sv.c b/sv.c index add445b..a5cb9e6 100644 --- a/sv.c +++ b/sv.c @@ -2774,10 +2774,6 @@ Perl_sv_setsv(pTHX_ SV *dstr, register SV *sstr) SvPV_set(dstr, SvPVX(sstr)); SvLEN_set(dstr, SvLEN(sstr)); SvCUR_set(dstr, SvCUR(sstr)); - if (SvUTF8(sstr)) - SvUTF8_on(dstr); - else - SvUTF8_off(dstr); SvTEMP_off(dstr); (void)SvOK_off(sstr); /* NOTE: nukes most SvFLAGS on sstr */ @@ -2795,7 +2791,7 @@ Perl_sv_setsv(pTHX_ SV *dstr, register SV *sstr) *SvEND(dstr) = '\0'; (void)SvPOK_only(dstr); } - if (DO_UTF8(sstr)) + if ((sflags & SVf_UTF8) && !IN_BYTE) SvUTF8_on(dstr); /*SUPPRESS 560*/ if (sflags & SVp_NOK) { diff --git a/t/op/quotemeta.t b/t/op/quotemeta.t index 60e5b7b..ec247f8 100755 --- a/t/op/quotemeta.t +++ b/t/op/quotemeta.t @@ -6,14 +6,14 @@ BEGIN { require Config; import Config; } -print "1..15\n"; +print "1..17\n"; if ($Config{ebcdic} eq 'define') { $_=join "", map chr($_), 129..233; # 105 characters - 52 letters = 53 backslashes # 105 characters + 53 backslashes = 158 characters - $_=quotemeta $_; + $_= quotemeta $_; if ( length == 158 ){print "ok 1\n"} else {print "not ok 1\n"} # 104 non-backslash characters if (tr/\\//cd == 104){print "ok 2\n"} else {print "not ok 2\n"} @@ -22,7 +22,7 @@ if ($Config{ebcdic} eq 'define') { # 96 characters - 52 letters - 10 digits - 1 underscore = 33 backslashes # 96 characters + 33 backslashes = 129 characters - $_=quotemeta $_; + $_= quotemeta $_; if ( length == 129 ){print "ok 1\n"} else {print "not ok 1\n"} # 95 non-backslash characters if (tr/\\//cd == 95){print "ok 2\n"} else {print "not ok 2\n"} @@ -42,3 +42,6 @@ print "\Q\u\LpE.X.R\EL\E." eq "Pe\\.x\\.rL." ? "ok 12\n" : "not ok 12 \n"; print "\Q\l\UPe*x*r\El\E*" eq "pE\\*X\\*Rl*" ? "ok 13\n" : "not ok 13 \n"; print "\U\lPerl\E\E\E\E" eq "pERL" ? "ok 14\n" : "not ok 14 \n"; print "\l\UPerl\E\E\E\E" eq "pERL" ? "ok 15\n" : "not ok 15 \n"; + +print length(quotemeta("\x{263a}")) == 1 ? "ok 16\n" : "not ok 16\n"; +print quotemeta("\x{263a}") eq "\x{263a}" ? "ok 17\n" : "not ok 17\n"; diff --git a/t/op/substr.t b/t/op/substr.t index a67eae5..d3668ac 100755 --- a/t/op/substr.t +++ b/t/op/substr.t @@ -1,10 +1,12 @@ +#!./perl -print "1..130\n"; +print "1..132\n"; #P = start of string Q = start of substr R = end of substr S = end of string BEGIN { - unshift @INC, '../lib' if -d '../lib' ; + chdir 't' if -d 't'; + unshift @INC, '../lib'; } use warnings ; @@ -272,12 +274,15 @@ ok 125, $a eq 'xxxxefgh'; # utf8 sanity { my $x = substr("a\x{263a}b",0); - ok 126, length($x) eq 3; + ok 126, length($x) == 3; $x = substr($x,1,1); ok 127, $x eq "\x{263a}"; $x = $x x 2; - ok 128, length($x) eq 2; + ok 128, length($x) == 2; substr($x,0,1) = "abcd"; ok 129, $x eq "abcd\x{263a}"; - ok 130, length($x) eq 5; + ok 130, length($x) == 5; + $x = reverse $x; + ok 131, length($x) == 5; + ok 132, $x eq "\x{263a}dcba"; } diff --git a/toke.c b/toke.c index 6af744c..b7ccedd 100644 --- a/toke.c +++ b/toke.c @@ -819,7 +819,7 @@ Perl_str_to_version(pTHX_ SV *sv) NV nshift = 1.0; STRLEN len; char *start = SvPVx(sv,len); - bool utf = SvUTF8(sv); + bool utf = SvUTF8(sv) ? TRUE : FALSE; char *end = start + len; while (start < end) { I32 skip;