summaryrefslogtreecommitdiff
path: root/pp_ctl.c
diff options
context:
space:
mode:
authorHauke D <haukex@zero-g.net>2018-11-30 13:06:07 +0100
committerTony Cook <tony@develop-help.com>2019-08-08 10:40:05 +1000
commitd1bc97feec1ac3a922c2ff2e27c9f517722cc565 (patch)
tree94e4420337336d66c898279bdaa2ce17a9c01d93 /pp_ctl.c
parent9bceefdb82ae645c3112967e6c233ed719b425f9 (diff)
downloadperl-d1bc97feec1ac3a922c2ff2e27c9f517722cc565.tar.gz
(perl #133695) "0".."-1" should act like 0..-1
Previously, *any* string beginning with 0, including the string "0" itself, would be subject to the magic string auto-increment, instead of being treated like a number. This meant that "-2".."-1" was the same as -2..-1 and "1".."-1" was the same as 1..-1, but "0".."-1" was the same as "0".."99". This patch fixes that inconsistency, while still allowing ranges like "01".."31" to produce the strings "01", "02", ... "31", which is what the "begins with 0" exception was intended for. This patch also expands the documentation in perlop and states the rules for the range operator in list context with both operands being strings more explicitly. See also #18165 and #18114.
Diffstat (limited to 'pp_ctl.c')
-rw-r--r--pp_ctl.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/pp_ctl.c b/pp_ctl.c
index a38b9c19b2..6fedac38fa 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -1178,14 +1178,18 @@ PP(pp_flip)
}
/* This code tries to decide if "$left .. $right" should use the
- magical string increment, or if the range is numeric (we make
- an exception for .."0" [#18165]). AMS 20021031. */
+ magical string increment, or if the range is numeric. Initially,
+ an exception was made for *any* string beginning with "0" (see
+ [#18165], AMS 20021031), but now that is only applied when the
+ string's length is also >1 - see the rules now documented in
+ perlop [#133695] */
#define RANGE_IS_NUMERIC(left,right) ( \
SvNIOKp(left) || (SvOK(left) && !SvPOKp(left)) || \
SvNIOKp(right) || (SvOK(right) && !SvPOKp(right)) || \
(((!SvOK(left) && SvOK(right)) || ((!SvOK(left) || \
- looks_like_number(left)) && SvPOKp(left) && *SvPVX_const(left) != '0')) \
+ looks_like_number(left)) && SvPOKp(left) \
+ && !(*SvPVX_const(left) == '0' && SvCUR(left)>1 ) )) \
&& (!SvOK(right) || looks_like_number(right))))
PP(pp_flop)