File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff 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 \xbf msgid "Python"\n msgstr "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 ('''\
Original file line number Diff line number Diff line change 3232import struct
3333import array
3434from email .parser import HeaderParser
35+ import codecs
3536
3637__version__ = "1.2"
3738
39+
3840MESSAGES = {}
3941
4042
@@ -116,6 +118,14 @@ def make(filename, outfile):
116118 print (msg , file = sys .stderr )
117119 sys .exit (1 )
118120
121+ if lines [0 ].startswith (codecs .BOM_UTF8 ):
122+ print (
123+ f"The file { infile } starts with a UTF-8 BOM which is not allowed in .po files.\n "
124+ "Please save the file without a BOM and try again." ,
125+ file = sys .stderr
126+ )
127+ sys .exit (1 )
128+
119129 section = msgctxt = None
120130 fuzzy = 0
121131
You can’t perform that action at this time.
0 commit comments