Skip to content

Commit 2455bff

Browse files
Apply Seirhy suggestions
1 parent 90f0e34 commit 2455bff

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Lib/test/test_tools/test_msgfmt.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ def test_compilation(self):
3939

4040
self.assertDictEqual(actual._catalog, expected._catalog)
4141

42+
def test_po_with_bom(self):
43+
with temp_cwd():
44+
Path('bom.po').write_bytes(b'\xef\xbb\xbfmsgid "Python"\nmsgstr "Pioton"\n')
45+
46+
res = assert_python_failure(msgfmt, 'bom.po')
47+
err = res.err.decode('utf-8')
48+
self.assertIn('The file bom.po starts with a UTF-8 BOM', err)
49+
4250
def test_invalid_msgid_plural(self):
4351
with temp_cwd():
4452
Path('invalid.po').write_text('''\

Tools/i18n/msgfmt.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
__version__ = "1.2"
3737

38+
import codecs
39+
3840
MESSAGES = {}
3941

4042

@@ -117,7 +119,7 @@ def make(filename, outfile):
117119
sys.exit(1)
118120

119121
# Check for UTF-8 BOM
120-
if lines[0].startswith(b'\xef\xbb\xbf'):
122+
if lines[0].startswith(codecs.BOM_UTF8):
121123
print(
122124
f"The file {infile} starts with a UTF-8 BOM which is not allowed in .po files.\n"
123125
"Please save the file without a BOM and try again.",

0 commit comments

Comments
 (0)