Skip to content

Commit c8c8e58

Browse files
John PeacockFather Chrysostomos
authored andcommitted
Revise check for negative versions plus test
1 parent 005700e commit c8c8e58

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

lib/version.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use strict;
66

77
use vars qw(@ISA $VERSION $CLASS $STRICT $LAX *declare *qv);
88

9-
$VERSION = 0.88;
9+
$VERSION = 0.92;
1010

1111
$CLASS = 'version';
1212

lib/version.t

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ sub BaseTests {
213213
like($@, qr/non-numeric data/,
214214
"Invalid version format (non-numeric data)");
215215

216+
eval { $version = $CLASS->$method("-1.23")};
217+
like($@, qr/negative version number/,
218+
"Invalid version format (negative version number)");
219+
216220
# from here on out capture the warning and test independently
217221
{
218222
eval{$version = $CLASS->$method("99 and 44/100 pure")};

util.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4541,6 +4541,11 @@ Perl_prescan_version(pTHX_ const char *s, bool strict,
45414541
}
45424542
}
45434543

4544+
/* and we never support negative versions */
4545+
if ( *d == '-') {
4546+
BADVERSION(s,errstr,"Invalid version format (negative version number)");
4547+
}
4548+
45444549
/* consume all of the integer part */
45454550
while (isDIGIT(*d))
45464551
d++;
@@ -4559,9 +4564,6 @@ Perl_prescan_version(pTHX_ const char *s, bool strict,
45594564
/* found just an integer */
45604565
goto version_prescan_finish;
45614566
}
4562-
else if ( *d == '-') {
4563-
BADVERSION(s,errstr,"Invalid version format (negative version number)");
4564-
}
45654567
else if ( d == s ) {
45664568
/* didn't find either integer or period */
45674569
BADVERSION(s,errstr,"Invalid version format (non-numeric data)");

0 commit comments

Comments
 (0)