Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on a very small (or large) version, do not index #399

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions lib/PAUSE/pmfile.pm
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,28 @@ sub parse_version {
sub normalize_version {
my($self,$v) = @_;
$v = "undef" unless defined $v;

# What on earth is this hunk about? Well, if the user has written
#
# $VERSION = 0.000001
#
# ...instead of...
#
# $VERSION = '0.000001'
#
# ...then when we eval the version value, we get a number. That's bad,
# because we'll lose fidelity. Sometimes this only means that 1.100
# becomes 1.1, but the worse case is when a version like 0.000001 becomes
# 1e-6, which then can't be turned into a version object with version->new.
#
# If the stringified version appears to be scientific notation, format it
# back into expanded form and make a version of that.
my $dv = Dumpvalue->new;
my $sdv = $dv->stringify($v,1); # second argument prevents ticks
$Logger->log("result of normalize_version: $sdv");
my $sdv = $dv->stringify($v, 1); # second argument prevents ticks
if ($sdv =~ /\A[0-9](?:\.[0-9]+)?e([-+])?[0-9]+\z/a) {
my $adj = $1 eq '-' ? 'small' : 'large';
die "very large or small numeric version; you must use a string in your source\n";
}

return $v if $v eq "undef";
return $v if $v =~ /^\{.*\}$/; # JSON object
Expand Down
23 changes: 23 additions & 0 deletions t/mldistwatch-misc.t
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,29 @@ subtest "do not index dists without META file" => sub {
);
};

subtest "very small version number (as numeric literal)" => sub {
my $pause = PAUSE::TestPAUSE->init_new;
$pause->upload_author_fake(PERSON => 'Tiny-Version-1.002.tar.gz', {
packages => [
'Tiny::Version' => {
version => '0.000001',
layout => { version => 'our-literal' },
},
],
});

my $result = $pause->test_reindex;

$pause->file_not_updated_ok(
$result->tmpdir
->file(qw(cpan modules 02packages.details.txt.gz)),
"there were no things to update",
);

local $TODO = "sending a useful warning here is more or less impossible";
fail("assert a report was sent with an explanation");
};

done_testing;

# Local Variables:
Expand Down