1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
see https://bugs.gentoo.org/977413
Backport patches for validation of language codes
patch-1:
https://github.com/bleachbit/bleachbit/commit/f105e2a.patch
Improve validation of language codes
patch-2:
https://github.com/bleachbit/bleachbit/pull/2159.patch
use POSIX locale order for validation
--- a/tests/TestCommon.py
+++ b/tests/TestCommon.py
@@ -38,6 +38,8 @@ def test_assertIsLanguageCode_hardcoded(self):
'C.utf8',
'C',
'de_DE.iso88591',
+ 'de-CH', # seen in Fedora in Docker
+ 'en-US',
'en_US',
'en',
'fr_FR.utf8',
@@ -49,7 +51,7 @@ def test_assertIsLanguageCode_hardcoded(self):
'zh_Hant',
]
- invalid_codes = ['e', 'en_', 'english', 'en_US_', '123', 'en-US',
+ invalid_codes = ['e', 'en_', 'english', 'en_US_', '123',
'en_us', 'en_US.',
'en_us.utf8',
'en_us.UTF-8',
@@ -76,12 +78,16 @@ def test_assertIsLanguageCode_live(self):
from bleachbit import locale_dir
locale_dirs = list(set([locale_dir, '/usr/share/locale']))
lang_codes = []
+ # Skip directories that are not valid language codes
+ skip_dirs = {'l10n'}
for locale_dir in locale_dirs:
if not os.path.isdir(locale_dir):
continue
for lang_code in os.listdir(locale_dir):
if not os.path.isdir(os.path.join(locale_dir, lang_code)):
continue
+ if lang_code in skip_dirs:
+ continue
lang_codes.append(lang_code)
if os.path.exists('/etc/locale.alias'):
with open('/etc/locale.alias', 'r') as f:
@@ -91,7 +97,13 @@ def test_assertIsLanguageCode_live(self):
parts = line.split()
if len(parts) > 1:
lang_codes.append(parts[1])
+ # /etc/locale.alias may list the qaa-qtz range, which is reserved for
+ # private use rather than a concrete locale. Skip it if present.
+ skip_alias_codes = {'qaa-qtz'}
+
for lang_code in lang_codes:
+ if lang_code in skip_alias_codes:
+ continue
self.assertIsLanguageCode(lang_code)
def test_environment(self):
--- a/tests/TestLanguage.py
+++ b/tests/TestLanguage.py
@@ -106,7 +106,7 @@ def test_get_text_all(self):
@skipIfMissingPo
def test_get_text_au(self):
- """Test Austrlian English
+ """Test Australian English
It should not get confused with American English.
"""
--- a/tests/common.py
+++ b/tests/common.py
@@ -125,7 +125,7 @@ class BleachbitTestCase(unittest.TestCase):
return
self.assertTrue(len(lang_id) >= 2)
import re
- pattern = r'^[a-z]{2,3}(_[A-Z][A-Za-z]{1,3})?(@\w+)?(\.[a-zA-Z][a-zA-Z0-9-]+)?$'
+ pattern = r'^[a-z]{2,3}([_-][A-Z][A-Za-z]{1,3})?(\.[a-zA-Z][a-zA-Z0-9-]+)?(@\w+)?$'
self.assertTrue(re.match(pattern, lang_id),
f'Invalid language code format: {lang_id}')
|