Skip to content
This repository has been archived by the owner on Apr 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #43 from techman83/fix-url_hash
Browse files Browse the repository at this point in the history
Fix url_hash - closes #42
  • Loading branch information
techman83 committed May 18, 2016
2 parents 4926a10 + ddbe0d5 commit dac6bcb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/App/KSP_CKAN/Metadata/Ckan.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use Config::JSON; # Saves us from file handling
use List::MoreUtils 'any';
use Carp qw( croak );
use Digest::SHA 'sha1_hex';
use URI::Escape 'uri_unescape';
use Scalar::Util 'reftype';
use Moo;
use namespace::clean;
Expand Down Expand Up @@ -245,7 +246,7 @@ method 'CreateURLHash'.
=cut

method url_hash {
my $hash = sha1_hex($self->download);
my $hash = sha1_hex(uri_unescape($self->download));
$hash =~ s/-//g;
return uc(substr $hash, 0, 8);
}
Expand Down
3 changes: 3 additions & 0 deletions t/App/KSP_CKAN/Metadata/Ckan.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use_ok("App::KSP_CKAN::Metadata::Ckan");
$test->create_ckan( file => $test->tmp."/package.ckan", random => 0 );
$test->create_ckan( file => $test->tmp."/metapackage.ckan", kind => "metapackage" );
$test->create_ckan( file => $test->tmp."/nohash.ckan", kind => "nohash" );
$test->create_ckan( file => $test->tmp."/escaped.ckan", download => 'https://example.com/url%20with%40escape%24characters%23' );
$test->create_ckan( file => $test->tmp."/no_mirror.ckan", license => '"restricted"', download => "");
$test->create_ckan( file => $test->tmp."/hash.ckan", download => "https://github.com/pjf/DogeCoinFlag/releases/download/v1.02/DogeCoinFlag-1.02.zip", license => '[ "restricted", "GPL-2.0" ]' );

Expand Down Expand Up @@ -49,6 +50,7 @@ subtest 'metapackage' => sub {
my $no_mirror = App::KSP_CKAN::Metadata::Ckan->new( file => $test->tmp."/no_mirror.ckan" );
my $hash = App::KSP_CKAN::Metadata::Ckan->new( file => $test->tmp."/hash.ckan" );
my $no_hash = App::KSP_CKAN::Metadata::Ckan->new( file => $test->tmp."/nohash.ckan");
my $escaped = App::KSP_CKAN::Metadata::Ckan->new( file => $test->tmp."/escaped.ckan");
subtest 'mirror' => sub {
# Can mirror
is($package->can_mirror, 1, "Package can be mirrored");
Expand All @@ -60,6 +62,7 @@ subtest 'mirror' => sub {

# Hashes
is($hash->url_hash, "6F8BEBCB", "Hash '".$hash->url_hash."' calculated correctly");
is($escaped->url_hash, "4CB16814", "Hash '".$escaped->url_hash."' calculated correctly from encoded URL - #42");

# Filenames
is(
Expand Down

0 comments on commit dac6bcb

Please sign in to comment.