[devscripts] 03/03: licensecheck: don't die when --encoding is wrong
dod at debian.org
dod at debian.org
Fri Mar 25 13:17:44 UTC 2016
This is an automated email from the git hooks/post-receive script.
dod pushed a commit to branch master
in repository devscripts.
commit 2dbe747c5af80a2690d351a0e1d978096ee5b18d
Author: Dominique Dumont <dod at debian.org>
Date: Fri Mar 25 14:09:33 2016 +0100
licensecheck: don't die when --encoding is wrong
Turns out that licensecheck died with --encoding utf8 option was used
to read a latin1 file (or any ISO encoding) with this error:
utf8 "\xFC" does not map to Unicode at /usr/bin/licensecheck line 415
This behavior breaks "cme update dpkg-copyright" when some files are
encoded in latin1 (cme always use --encoding utf8 option).
When --encoding is used, licensecheck will now attempt to read the file
with latin1 and then binary encoding.
---
scripts/licensecheck.pl | 24 +++++++++++++++++++++++-
test/test_licensecheck | 3 +++
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/scripts/licensecheck.pl b/scripts/licensecheck.pl
index 16d3ef4..e1d8f1f 100755
--- a/scripts/licensecheck.pl
+++ b/scripts/licensecheck.pl
@@ -404,7 +404,29 @@ while (@files) {
my $enc = $OPT{encoding} ;
- my ($license, $copyright) = parse_file($file, $enc) ;
+ my ($license, $copyright) ;
+
+ my $ok = 0;
+ my @try = $enc ? ($enc, 'latin-1', undef) : (undef);
+
+ while (not $ok and @try) {
+ my $try_enc = shift @try;
+
+ eval { ($license, $copyright) = parse_file($file, $try_enc) ; };
+
+ if ($@ and $@ =~ /does not map to Unicode/) {
+ my $str_enc = $enc // 'binary';
+ my $next_enc = $try[0] // 'binary';
+ print "file $file cannot be read with $str_enc encoding, will try $next_enc:\n$@"
+ if $OPT{'verbose'};
+ }
+ elsif ($@) {
+ die $@;
+ }
+ else {
+ last;
+ }
+ }
if ($OPT{'machine'}) {
print "$file\t$license";
diff --git a/test/test_licensecheck b/test/test_licensecheck
index 0a9a504..3ede643 100755
--- a/test/test_licensecheck
+++ b/test/test_licensecheck
@@ -159,6 +159,9 @@ testRegexpKiller() {
testEncoding () {
license2 "-m --copyright --encoding iso-8859-1" "copr-iso8859.h" "GPL (v2) (with incorrect FSF address) 2011 Heinrich Müller <henmull at src.gnome.org>"
license2 "-m --copyright --encoding utf8" "copr-utf8.h" "GPL (v2 or later) 2004-2015 Oliva 'f00' Oberto / 2001-2010 Paul 'bar' Stevénsön"
+
+ # test wrong user choice and fallback
+ license2 "-m --copyright --encoding utf8" "copr-iso8859.h" "GPL (v2) (with incorrect FSF address) 2011 Heinrich Müller <henmull at src.gnome.org>"
}
testInfoAtEnd () {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/devscripts.git
More information about the devscripts-devel
mailing list