summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pp_ctl.c6
-rwxr-xr-xt/op/range.t12
2 files changed, 14 insertions, 4 deletions
diff --git a/pp_ctl.c b/pp_ctl.c
index ab4ab84c3c..ec79e24936 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 a4f03c5a72..d54c96d11f 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";