From: Aarni Koskela Date: Mon, 27 May 2019 08:01:38 +0000 (+0300) Subject: get_display_name(): Don't attempt to concatenate variant information to None X-Git-Tag: v2.7.0~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4fa0c6e5a2d3ae4c10ca160dabe4e3d169dace81;p=thirdparty%2Fbabel.git get_display_name(): Don't attempt to concatenate variant information to None Fixes #601 --- diff --git a/babel/core.py b/babel/core.py index d028c07d..211849bc 100644 --- a/babel/core.py +++ b/babel/core.py @@ -379,7 +379,7 @@ class Locale(object): locale = self locale = Locale.parse(locale) retval = locale.languages.get(self.language) - if self.territory or self.script or self.variant: + if retval and (self.territory or self.script or self.variant): details = [] if self.script: details.append(locale.scripts.get(self.script)) diff --git a/tests/test_core.py b/tests/test_core.py index f22ab309..fc637d24 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -317,3 +317,13 @@ def test_compatible_classes_in_global_and_localedata(filename): with open(filename, 'rb') as f: return Unpickler(f).load() + + +def test_issue_601_no_language_name_but_has_variant(): + # kw_GB has a variant for Finnish but no actual language name for Finnish, + # so `get_display_name()` previously crashed with a TypeError as it attempted + # to concatenate " (Finnish)" to None. + # Instead, it's better to return None altogether, as we can't reliably format + # part of a language name. + + assert Locale.parse('fi_FI').get_display_name('kw_GB') == None