diff options
author | Walter Lozano <walter.lozano@collabora.com> | 2021-03-31 23:11:29 -0300 |
---|---|---|
committer | Walter Lozano <walter.lozano@collabora.com> | 2021-05-25 12:40:53 -0300 |
commit | 54bae3f061e5d62956ae859220e8d59f34b31788 (patch) | |
tree | e6aeee3379454b9f529e4501681ae783458618fc | |
parent | 471c24eb2654ebc8c2b1dcdfb21d677ef6ce736f (diff) |
Support "author" as object in package.json
While getting "author" from package.json the expected values are string or
lists. However some packages like less.js present an object as value.
As an example here is how "author" is declared in less.js
"author": {
"name": "Alexis Sellier",
"email": "self@cloudhead.net"
},
Add support to this by retrieving the value of key "name" in that case.
Signed-off-by: Walter Lozano <walter.lozano@collabora.com>
-rw-r--r-- | lib/Dpkg/Copyright/Scanner.pm | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/Dpkg/Copyright/Scanner.pm b/lib/Dpkg/Copyright/Scanner.pm index 5f5aa937..2671efec 100644 --- a/lib/Dpkg/Copyright/Scanner.pm +++ b/lib/Dpkg/Copyright/Scanner.pm @@ -291,6 +291,34 @@ my $__extract_rust_info = sub ($file, $c, $l, $current_dir) { return ($c, $l); }; +my $__extract_nodejs_info = sub ($c_key, $l_key, $file, $c, $l, $current_dir) { + my $json_file = $current_dir->child($file); + + if ($json_file->is_file) { + my $data = decode_json($json_file->slurp_utf8); + + my @c_data; + if (ref $data->{$c_key}) { + if (ref $data->{$c_key} eq 'HASH') { + if (exists($data->{$c_key}->{name})) { + @c_data = ($data->{$c_key}->{name}); + } + } + else { + @c_data = ($data->{$c_key}->@*); + } + } else { + @c_data = ($data->{$c_key}); + } + + my @l_data + = ref $data->{$l_key} eq 'ARRAY' ? $data->{$l_key}->@* + : $data->{$l_key}; + return (join("\n ", @c_data) || $c, join(" or ",@l_data) || $l); + } + return ($c, $l); +}; + my $__extract_json_info = sub ($c_key, $l_key, $file, $c, $l, $current_dir) { my $json_file = $current_dir->child($file); @@ -305,7 +333,7 @@ my $__extract_json_info = sub ($c_key, $l_key, $file, $c, $l, $current_dir) { my %override = ( 'Cargo.toml' => $__extract_rust_info, - 'package.json' => sub {$__extract_json_info->('author','license',@_)}, + 'package.json' => sub {$__extract_nodejs_info->('author','license',@_)}, 'META.json' => sub {$__extract_json_info->('author','license',@_)}, 'META6.json' => sub {$__extract_json_info->('authors','license',@_)}, ); |