From: Rafael Garcia-Suarez Date: Sat, 27 Dec 2003 21:29:04 +0000 (+0000) Subject: Fix bug [perl #24735] : make sure that the range (..) operator X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b0e74086c793b91e11f2cb4f6e6cda6343532701;p=p5sagit%2Fp5-mst-13.2.git Fix bug [perl #24735] : make sure that the range (..) operator treats an undefined argument as 0 for numerical ranges and as "" for magical string ranges. p4raw-id: //depot/perl@21983 --- diff --git a/pp_ctl.c b/pp_ctl.c index ab4ab84..ec79e24 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -1036,9 +1036,9 @@ PP(pp_flip) an exception for .."0" [#18165]). AMS 20021031. */ #define RANGE_IS_NUMERIC(left,right) ( \ - SvNIOKp(left) || !SvPOKp(left) || \ - SvNIOKp(right) || !SvPOKp(right) || \ - (looks_like_number(left) && *SvPVX(left) != '0' && \ + SvNIOKp(left) || (SvOK(left) && !SvPOKp(left)) || \ + SvNIOKp(right) || (SvOK(right) && !SvPOKp(right)) || \ + (looks_like_number(left) && SvPOKp(left) && *SvPVX(left) != '0' && \ looks_like_number(right))) PP(pp_flop) diff --git a/t/op/range.t b/t/op/range.t index a4f03c5..d54c96d 100755 --- a/t/op/range.t +++ b/t/op/range.t @@ -1,6 +1,6 @@ #!./perl -print "1..19\n"; +print "1..25\n"; print join(':',1..5) eq '1:2:3:4:5' ? "ok 1\n" : "not ok 1\n"; @@ -79,3 +79,13 @@ print join(":","-4".."0") eq "-4:-3:-2:-1:0" ? "ok 16\n" : "not ok 16\n"; print join(":","-4".."-0") eq "-4:-3:-2:-1:0" ? "ok 17\n" : "not ok 17\n"; print join(":","-4\n".."0\n") eq "-4:-3:-2:-1:0" ? "ok 18\n" : "not ok 18\n"; print join(":","-4\n".."-0\n") eq "-4:-3:-2:-1:0" ? "ok 19\n" : "not ok 19\n"; + +# undef should be treated as 0 for numerical range +print join(":",undef..2) eq '0:1:2' ? "ok 20\n" : "not ok 20\n"; +print join(":",-2..undef) eq '-2:-1:0' ? "ok 21\n" : "not ok 21\n"; + +# undef should be treated as "" for magical range +print join(":","".."B") eq '' ? "ok 22\n" : "not ok 22\n"; +print join(":",undef.."B") eq '' ? "ok 23\n" : "not ok 23\n"; +print join(":","B".."") eq '' ? "ok 24\n" : "not ok 24\n"; +print join(":","B"..undef) eq '' ? "ok 25\n" : "not ok 25\n";