Skip to content

Commit 0774909

Browse files
committed
on a very small (or large) version, do not index
Really, this should become a useful user message, but it's painfully difficult to get that error up through the call stack. This code needs (in my opinion) to be rearchitected to make this sort of thing simple. In the meantime, the code now detects this case specifically, so we can do something about it later.
1 parent a87299b commit 0774909

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

lib/PAUSE/pmfile.pm

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,28 @@ sub parse_version {
569569
sub normalize_version {
570570
my($self,$v) = @_;
571571
$v = "undef" unless defined $v;
572+
573+
# What on earth is this hunk about? Well, if the user has written
574+
#
575+
# $VERSION = 0.000001
576+
#
577+
# ...instead of...
578+
#
579+
# $VERSION = '0.000001'
580+
#
581+
# ...then when we eval the version value, we get a number. That's bad,
582+
# because we'll lose fidelity. Sometimes this only means that 1.100
583+
# becomes 1.1, but the worse case is when a version like 0.000001 becomes
584+
# 1e-6, which then can't be turned into a version object with version->new.
585+
#
586+
# If the stringified version appears to be scientific notation, format it
587+
# back into expanded form and make a version of that.
572588
my $dv = Dumpvalue->new;
573-
my $sdv = $dv->stringify($v,1); # second argument prevents ticks
574-
$Logger->log("result of normalize_version: $sdv");
589+
my $sdv = $dv->stringify($v, 1); # second argument prevents ticks
590+
if ($sdv =~ /\A[0-9](?:\.[0-9]+)?e([-+])?[0-9]+\z/a) {
591+
my $adj = $1 eq '-' ? 'small' : 'large';
592+
die "very large or small numeric version; you must use a string in your source\n";
593+
}
575594
576595
return $v if $v eq "undef";
577596
return $v if $v =~ /^\{.*\}$/; # JSON object

t/mldistwatch-misc.t

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,29 @@ subtest "do not index dists without META file" => sub {
581581
);
582582
};
583583

584+
subtest "very small version number (as numeric literal)" => sub {
585+
my $pause = PAUSE::TestPAUSE->init_new;
586+
$pause->upload_author_fake(PERSON => 'Tiny-Version-1.002.tar.gz', {
587+
packages => [
588+
'Tiny::Version' => {
589+
version => '0.000001',
590+
layout => { version => 'our-literal' },
591+
},
592+
],
593+
});
594+
595+
my $result = $pause->test_reindex;
596+
597+
$pause->file_not_updated_ok(
598+
$result->tmpdir
599+
->file(qw(cpan modules 02packages.details.txt.gz)),
600+
"there were no things to update",
601+
);
602+
603+
local $TODO = "sending a useful warning here is more or less impossible";
604+
fail("assert a report was sent with an explanation");
605+
};
606+
584607
done_testing;
585608

586609
# Local Variables:

0 commit comments

Comments
 (0)