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):
39
39
40
40
self .assertDictEqual (actual ._catalog , expected ._catalog )
41
41
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
+
42
50
def test_invalid_msgid_plural (self ):
43
51
with temp_cwd ():
44
52
Path ('invalid.po' ).write_text ('''\
Original file line number Diff line number Diff line change 32
32
import struct
33
33
import array
34
34
from email .parser import HeaderParser
35
+ import codecs
35
36
36
37
__version__ = "1.2"
37
38
39
+
38
40
MESSAGES = {}
39
41
40
42
@@ -116,6 +118,14 @@ def make(filename, outfile):
116
118
print (msg , file = sys .stderr )
117
119
sys .exit (1 )
118
120
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
+
119
129
section = msgctxt = None
120
130
fuzzy = 0
121
131
You can’t perform that action at this time.
0 commit comments