From e38171cf57fef8a0f4063d9e539998f145135ade Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Wed, 6 Jun 2012 12:49:05 -0700 Subject: [PATCH] Fix perl #57706 for magical vars: -"-10" MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Commit a5b92898 caused -"-10" to return 10, not "+10". But it wasn’t working for magical variables. SvIV_please_nomg was fixed recently for magical variables, but not SvIV_please, so change pp_negate to use that. (Ironically, SvIV_please has never called magic, so the SvIV_please_nomg variant never needed to exist. So the two could be merged.) --- pp.c | 2 +- t/op/negate.t | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pp.c b/pp.c index 48fd8c6..38505bc 100644 --- a/pp.c +++ b/pp.c @@ -2158,7 +2158,7 @@ PP(pp_negate) SV * const sv = TOPs; if( !SvNIOK( sv ) && looks_like_number( sv ) ){ - SvIV_please( sv ); + SvIV_please_nomg( sv ); } if (SvIOK(sv) || (SvOKp(sv) == SVp_IOK)) { diff --git a/t/op/negate.t b/t/op/negate.t index 62dc418..0249cb2 100644 --- a/t/op/negate.t +++ b/t/op/negate.t @@ -6,7 +6,7 @@ BEGIN { require './test.pl'; } -plan tests => 18; +plan tests => 20; # Some of these will cause warnings if left on. Here we're checking the # functionality, not the warnings. @@ -19,7 +19,11 @@ is(-"10", -10, "Negation of a positive string to negative"); is(-"10.0", -10, "Negation of a positive decimal sting to negative"); is(-"10foo", -10, "Negation of a numeric-lead string returns negation of numeric"); is(-"-10", 10, 'Negation of string starting with "-" returns a positive number - integer'); +"-10" =~ /(.*)/; +is(-$1, 10, 'Negation of magical string starting with "-" - integer'); is(-"-10.0", 10.0, 'Negation of string starting with "-" returns a positive number - decimal'); +"-10.0" =~ /(.*)/; +is(-$1, 10.0, 'Negation of magical string starting with "-" - decimal'); is(-"-10foo", "+10foo", 'Negation of string starting with "-" returns a string starting with "+" - non-numeric'); is(-"xyz", "-xyz", 'Negation of a negative string adds "-" to the front'); is(-"-xyz", "+xyz", "Negation of a negative string to positive"); -- 1.8.3.1