diff --git a/Changes b/Changes index 7e82b3b..84ddf3a 100644 --- a/Changes +++ b/Changes @@ -1,10 +1,15 @@ Revision history for Perl extension URI::PackageURL. +1.10 2022-08-01 + - Fixed "namespace vs name" (RT#143917) + - Fixed substitution warning when "version" component is not provided + in URI::PackageURL->from_string + 1.02 2022-07-31 - - Fix decode when "namespace" component is undef + - Fixed decode when "namespace" component is "undef" 1.01 2022-07-26 - - Fix documentation and test prerequisite (JSON::PP) + - Fixed documentation and test prerequisite (JSON::PP) 1.00 2022-07-25 - First release of URI::PackageURL diff --git a/lib/URI/PackageURL.pm b/lib/URI/PackageURL.pm index 0129f43..c1ffbb1 100644 --- a/lib/URI/PackageURL.pm +++ b/lib/URI/PackageURL.pm @@ -12,7 +12,7 @@ use constant DEBUG => $ENV{PURL_DEBUG}; use overload '""' => 'to_string', fallback => 1; -our $VERSION = '1.02'; +our $VERSION = '1.10'; our @EXPORT = qw(encode_purl decode_purl); @@ -56,19 +56,12 @@ sub normalize_components { $components{type} = lc $components{type}; - if ($components{type} eq 'pypi') { - $components{name} =~ s/_/-/g; + if ($components{type} eq 'cpan') { + $components{name} =~ s/-/::/g; } - # CPAN: Split Perl "Namespace::Package" naming into "namespace" and "name" components - if ($components{type} eq 'cpan' && $components{name} =~ /::/) { - - my @ns = split /::/, $components{name}; - my $name = pop @ns; - - $components{name} = $name; - $components{namespace} = join '::', @ns; - + if ($components{type} eq 'pypi') { + $components{name} =~ s/_/-/g; } if (grep { $_ eq $components{type} } qw(bitbucket deb github golang hex npm pypi)) { @@ -203,7 +196,7 @@ sub from_string { # This is the version my @s5 = split('@', $s4[1]); - $components{version} = url_decode($s5[1]); + $components{version} = url_decode($s5[1]) if ($s5[1]); # Split the remainder once from right on '/' @@ -214,7 +207,7 @@ sub from_string { # This is the name my @s6 = split('/', $s5[0], 2); - $components{name} = (scalar @s6 > 1) ? url_decode($s6[1]) : url_decode($s6[0]); + $components{name} = (scalar @s6 > 1) ? url_decode($s6[1]) : url_decode($s6[0]); # Split the remainder on '/' @@ -230,7 +223,6 @@ sub from_string { $components{namespace} = join '/', map { url_decode($_) } @s7; } - return $class->new(%components); } @@ -313,19 +305,19 @@ URI::PackageURL - Perl extension for Package URL (aka "purl") # OO-interface # Encode components in PackageURL string - $purl = URI::PackageURL->new(type => cpan, namespace => 'URI', name => 'PackageURL', version => 1.00'); + $purl = URI::PackageURL->new(type => cpan, name => 'URI::PackageURL', version => '1.10'); - say $purl; # pkg:cpan/URI/PackageURL@0.0.1 + say $purl; # pkg:cpan/URI::PackageURL@1.10 # Parse PackageURL string - $purl = URI::PackageURL->from_string('pkg:cpan/URI/PackageURL@0.0.1'); + $purl = URI::PackageURL->from_string('pkg:cpan/URI::PackageURL@1.10'); # exported funtions - $purl = decode_purl('pkg:cpan/URI/PackageURL@0.0.1'); + $purl = decode_purl('pkg:cpan/URI::PackageURL@1.10'); say $purl->type; # cpan - $purl_string = encode_purl(type => cpan, namespace => 'URI', name => 'PackageURL', version => 1.00'); + $purl_string = encode_purl(type => cpan, name => 'URI::PackageURL', version => '1.10'); =head1 DESCRIPTION @@ -437,7 +429,7 @@ Helper method for JSON modules (L, L, L, L use Mojo::JSON qw(encode_json); - say encode_json($purl); # {"name":"PackageURL","namespace":"URI","qualifiers":null,"subpath":null,"type":"cpan","version":"0.0.1"} + say encode_json($purl); # {"name":"URI::PackageURL","namespace":null,"qualifiers":null,"subpath":null,"type":"cpan","version":"1.10"} =back diff --git a/t/10-encode.t b/t/10-encode.t index dfa627b..ec99753 100644 --- a/t/10-encode.t +++ b/t/10-encode.t @@ -8,8 +8,8 @@ use Test::More; use URI::PackageURL qw(encode_purl); is( - encode_purl(type => 'cpan', name => 'URI::PackageURL', version => '1.00'), - 'pkg:cpan/URI/PackageURL@1.00', + encode_purl(type => 'cpan', name => 'URI::PackageURL', version => '1.10'), + 'pkg:cpan/URI::PackageURL@1.10', 'encode_purl()' ); diff --git a/t/20-decode.t b/t/20-decode.t index 15d73f3..a26c311 100644 --- a/t/20-decode.t +++ b/t/20-decode.t @@ -7,7 +7,7 @@ use Test::More; use URI::PackageURL; -my $t1 = 'pkg:cpan/URI/PackageURL@1.00'; +my $t1 = 'pkg:cpan/URI::PackageURL@1.10'; my $t2 = 'pkg:deb/debian/curl@7.50.3-1?arch=i386&distro=jessie'; my $t3 = 'pkg:golang/google.golang.org/genproto@abcdedf#googleapis/api/annotations'; my $t4 = 'pkg:docker/customer/dockerimage@sha256:244fd47e07d1004f0aed9c?repository_url=gcr.io'; @@ -16,10 +16,9 @@ subtest "Decode '$t1'" => sub { my $purl = decode_purl($t1); - is($purl->type, 'cpan', 'Type'); - is($purl->namespace, 'URI', 'Namespace'); - is($purl->name, 'PackageURL', 'Name'); - is($purl->version, '1.00', 'Version'); + is($purl->type, 'cpan', 'Type'); + is($purl->name, 'URI::PackageURL', 'Name'); + is($purl->version, '1.10', 'Version'); is($purl->to_string, $t1, 'PackageURL');