[pypy-commit] pypy default: Normalize encoding also when checking that it is "utf-8" after seeing a BOM

arigo pypy.commits at gmail.com
Wed Jun 26 12:18:06 EDT 2019


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r96867:9831511d5e3e
Date: 2019-06-26 18:17 +0200
http://bitbucket.org/pypy/pypy/changeset/9831511d5e3e/

Log:	Normalize encoding also when checking that it is "utf-8" after
	seeing a BOM

diff --git a/pypy/interpreter/pyparser/pyparse.py b/pypy/interpreter/pyparser/pyparse.py
--- a/pypy/interpreter/pyparser/pyparse.py
+++ b/pypy/interpreter/pyparser/pyparse.py
@@ -105,7 +105,7 @@
             enc = 'utf-8'
             # If an encoding is explicitly given check that it is utf-8.
             decl_enc = _check_for_encoding(textsrc)
-            if decl_enc and decl_enc != "utf-8":
+            if decl_enc and _normalize_encoding(decl_enc) != "utf-8":
                 raise error.SyntaxError("UTF-8 BOM with %s coding cookie" % decl_enc,
                                         filename=compile_info.filename)
         elif compile_info.flags & consts.PyCF_SOURCE_IS_UTF8:
diff --git a/pypy/interpreter/pyparser/test/test_pyparse.py b/pypy/interpreter/pyparser/test/test_pyparse.py
--- a/pypy/interpreter/pyparser/test/test_pyparse.py
+++ b/pypy/interpreter/pyparser/test/test_pyparse.py
@@ -56,6 +56,8 @@
         input = "\xEF\xBB\xBF# coding: latin-1\nx"
         exc = py.test.raises(SyntaxError, self.parse, input).value
         assert exc.msg == "UTF-8 BOM with latin-1 coding cookie"
+        input = "\xEF\xBB\xBF# coding: UtF-8-yadda-YADDA\nx"
+        self.parse(input)    # this does not raise
         input = "# coding: not-here"
         exc = py.test.raises(SyntaxError, self.parse, input).value
         assert exc.msg == "Unknown encoding: not-here"


More information about the pypy-commit mailing list