Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Lib/test/test_tools/test_msgfmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ def test_compilation(self):

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

def test_po_with_bom(self):
with temp_cwd():
Path('bom.po').write_bytes(b'\xef\xbb\xbfmsgid "Python"\nmsgstr "Pioton"\n')

res = assert_python_failure(msgfmt, 'bom.po')
err = res.err.decode('utf-8')
self.assertIn('The file bom.po starts with a UTF-8 BOM', err)

def test_invalid_msgid_plural(self):
with temp_cwd():
Path('invalid.po').write_text('''\
Expand Down
11 changes: 11 additions & 0 deletions Tools/i18n/msgfmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

__version__ = "1.2"

import codecs

MESSAGES = {}


Expand Down Expand Up @@ -116,6 +118,15 @@ def make(filename, outfile):
print(msg, file=sys.stderr)
sys.exit(1)

# Check for UTF-8 BOM
if lines[0].startswith(codecs.BOM_UTF8):
print(
f"The file {infile} starts with a UTF-8 BOM which is not allowed in .po files.\n"
"Please save the file without a BOM and try again.",
file=sys.stderr
)
sys.exit(1)

section = msgctxt = None
fuzzy = 0

Expand Down
Loading