Skip to content

Commit

Permalink
Item14406: Don't crash for Perl 5.26 Locale::Codes
Browse files Browse the repository at this point in the history
Add try/otherwise to catch any errors in the LANGUAGES.pm pluggable to
avoid issues on perl 5.26.   Also pass the $no_check_code flag
to prevent errors from being logged.
  • Loading branch information
gac410 committed May 24, 2017
1 parent 78f56bd commit a9205d0
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions core/lib/Foswiki/Configure/Pluggables/LANGUAGES.pm
Expand Up @@ -15,6 +15,7 @@ use warnings;

use Locale::Language ();
use Locale::Country ();
use Error qw{ :try };

use Assert;
use Foswiki::Configure::Load ();
Expand Down Expand Up @@ -43,26 +44,41 @@ sub construct {
$keys = "'$keys'" if $keys =~ m/\W/;

my $label;
if ( $lang =~ m/^(\w+)-(\w+)$/ ) {
my ( $lname, $cname ) = (
( Locale::Language::code2language($1) || '' ),
( Locale::Country::code2country($2) || '' )
);
if ( $lname && $cname ) {
$label = "$lname ($cname)";
}
elsif ($lname) {
$label = "$lname ($2)";
}
elsif ($cname) {
$label = "$1 ($cname)";

# SMELL: Language::Codes _code() is documented as taking a 3rd parameter, $no_check_code
# as useful when adding languages. Set no_check_code so we don't crash for unknown languages
# ie. Klingon. As of perl 5.26, it crashes for unkown languages.

try {
if ( $lang =~ m/^(\w+)-(\w+)$/ ) {
my ( $lname, $cname ) = (
( Locale::Language::code2language( $1, undef, 1 ) || '' ),
( Locale::Country::code2country( $2, undef, 1 ) || '' )
);
if ( $lname && $cname ) {
$label = "$lname ($cname)";
}
elsif ($lname) {
$label = "$lname ($2)";
}
elsif ($cname) {
$label = "$1 ($cname)";
}
else {
$label = "$lang";
}
}
else {
$label = "$lang";
$label = Locale::Language::code2language( $lang, undef, 1 )
|| "$lang";
}
}
else {
$label = Locale::Language::code2language($lang) || "$lang";
otherwise {
$label = $lang;
};

if ( $label eq 'tlh' ) {
$label = "Klingon";
}

my $value = Foswiki::Configure::Value->new(
Expand Down

0 comments on commit a9205d0

Please sign in to comment.