From c8c8e589d797908c16fc78c20698c3b606331e15 Mon Sep 17 00:00:00 2001 From: John Peacock Date: Fri, 1 Jul 2011 23:18:09 -0400 Subject: [PATCH] Revise check for negative versions plus test --- lib/version.pm | 2 +- lib/version.t | 4 ++++ util.c | 8 +++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/version.pm b/lib/version.pm index adeaacd..1126f91 100644 --- a/lib/version.pm +++ b/lib/version.pm @@ -6,7 +6,7 @@ use strict; use vars qw(@ISA $VERSION $CLASS $STRICT $LAX *declare *qv); -$VERSION = 0.88; +$VERSION = 0.92; $CLASS = 'version'; diff --git a/lib/version.t b/lib/version.t index d2e3a2b..bee9078 100644 --- a/lib/version.t +++ b/lib/version.t @@ -213,6 +213,10 @@ sub BaseTests { like($@, qr/non-numeric data/, "Invalid version format (non-numeric data)"); + eval { $version = $CLASS->$method("-1.23")}; + like($@, qr/negative version number/, + "Invalid version format (negative version number)"); + # from here on out capture the warning and test independently { eval{$version = $CLASS->$method("99 and 44/100 pure")}; diff --git a/util.c b/util.c index fcfeda9..e22a97f 100644 --- a/util.c +++ b/util.c @@ -4541,6 +4541,11 @@ dotted_decimal_version: } } + /* and we never support negative versions */ + if ( *d == '-') { + BADVERSION(s,errstr,"Invalid version format (negative version number)"); + } + /* consume all of the integer part */ while (isDIGIT(*d)) d++; @@ -4559,9 +4564,6 @@ dotted_decimal_version: /* found just an integer */ goto version_prescan_finish; } - else if ( *d == '-') { - BADVERSION(s,errstr,"Invalid version format (negative version number)"); - } else if ( d == s ) { /* didn't find either integer or period */ BADVERSION(s,errstr,"Invalid version format (non-numeric data)"); -- 2.7.4