Kaydet (Commit) db83eb31 authored tarafından Neal Norwitz's avatar Neal Norwitz

Fix Bug #1378022, UTF-8 files with a leading BOM crashed the interpreter.

Needs backport.
üst e7214a13
#coding: utf8
print '我'
\ No newline at end of file
...@@ -5,6 +5,13 @@ import os ...@@ -5,6 +5,13 @@ import os
class CodingTest(unittest.TestCase): class CodingTest(unittest.TestCase):
def test_bad_coding(self): def test_bad_coding(self):
module_name = 'bad_coding' module_name = 'bad_coding'
self.verify_bad_module(module_name)
def test_bad_coding2(self):
module_name = 'bad_coding2'
self.verify_bad_module(module_name)
def verify_bad_module(self, module_name):
self.assertRaises(SyntaxError, __import__, 'test.' + module_name) self.assertRaises(SyntaxError, __import__, 'test.' + module_name)
path = os.path.dirname(__file__) path = os.path.dirname(__file__)
......
...@@ -12,6 +12,8 @@ What's New in Python 2.5 alpha 1? ...@@ -12,6 +12,8 @@ What's New in Python 2.5 alpha 1?
Core and builtins Core and builtins
----------------- -----------------
- Bug #1378022, UTF-8 files with a leading BOM crashed the interpreter.
- Support for converting hex strings to floats no longer works. - Support for converting hex strings to floats no longer works.
This was not portable. float('0x3') now raises a ValueError. This was not portable. float('0x3') now raises a ValueError.
......
...@@ -292,6 +292,12 @@ check_coding_spec(const char* line, int size, struct tok_state *tok, ...@@ -292,6 +292,12 @@ check_coding_spec(const char* line, int size, struct tok_state *tok,
PyMem_DEL(cs); PyMem_DEL(cs);
} }
} }
if (!r) {
cs = tok->encoding;
if (!cs)
cs = "with BOM";
PyErr_Format(PyExc_SyntaxError, "encoding problem: %s", cs);
}
return r; return r;
} }
......
...@@ -1439,8 +1439,8 @@ err_input(perrdetail *err) ...@@ -1439,8 +1439,8 @@ err_input(perrdetail *err)
} }
if (msg == NULL) if (msg == NULL)
msg = "unknown decode error"; msg = "unknown decode error";
Py_DECREF(type); Py_XDECREF(type);
Py_DECREF(value); Py_XDECREF(value);
Py_XDECREF(tb); Py_XDECREF(tb);
break; break;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment