patch 680474 that fixes bug 679880: compile/eval/exec refused utf-8 bom
mark. Added unit test.
This commit is contained in:
parent
cf117b0b40
commit
f032f86e9e
|
@ -190,6 +190,8 @@ class BuiltinTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_compile(self):
|
def test_compile(self):
|
||||||
compile('print 1\n', '', 'exec')
|
compile('print 1\n', '', 'exec')
|
||||||
|
bom = '\xef\xbb\xbf'
|
||||||
|
compile(bom + 'print 1\n', '', 'exec')
|
||||||
self.assertRaises(TypeError, compile)
|
self.assertRaises(TypeError, compile)
|
||||||
self.assertRaises(ValueError, compile, 'print 42\n', '<string>', 'badmode')
|
self.assertRaises(ValueError, compile, 'print 42\n', '<string>', 'badmode')
|
||||||
self.assertRaises(ValueError, compile, 'print 42\n', '<string>', 'single', 0xff)
|
self.assertRaises(ValueError, compile, 'print 42\n', '<string>', 'single', 0xff)
|
||||||
|
@ -305,6 +307,8 @@ class BuiltinTest(unittest.TestCase):
|
||||||
self.assertEqual(eval(unicode('a'), globals, locals), 1)
|
self.assertEqual(eval(unicode('a'), globals, locals), 1)
|
||||||
self.assertEqual(eval(unicode('b'), globals, locals), 200)
|
self.assertEqual(eval(unicode('b'), globals, locals), 200)
|
||||||
self.assertEqual(eval(unicode('c'), globals, locals), 300)
|
self.assertEqual(eval(unicode('c'), globals, locals), 300)
|
||||||
|
bom = '\xef\xbb\xbf'
|
||||||
|
self.assertEqual(eval(bom + 'a', globals, locals), 1)
|
||||||
self.assertRaises(TypeError, eval)
|
self.assertRaises(TypeError, eval)
|
||||||
self.assertRaises(TypeError, eval, ())
|
self.assertRaises(TypeError, eval, ())
|
||||||
|
|
||||||
|
|
|
@ -506,14 +506,14 @@ decoding_feof(struct tok_state *tok)
|
||||||
/* Fetch a byte from TOK, using the string buffer. */
|
/* Fetch a byte from TOK, using the string buffer. */
|
||||||
|
|
||||||
static int buf_getc(struct tok_state *tok) {
|
static int buf_getc(struct tok_state *tok) {
|
||||||
return *tok->str++;
|
return Py_CHARMASK(*tok->str++);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unfetch a byte from TOK, using the string buffer. */
|
/* Unfetch a byte from TOK, using the string buffer. */
|
||||||
|
|
||||||
static void buf_ungetc(int c, struct tok_state *tok) {
|
static void buf_ungetc(int c, struct tok_state *tok) {
|
||||||
tok->str--;
|
tok->str--;
|
||||||
assert(*tok->str == c); /* tok->cur may point to read-only segment */
|
assert(Py_CHARMASK(*tok->str) == c); /* tok->cur may point to read-only segment */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the readline function for TOK to ENC. For the string-based
|
/* Set the readline function for TOK to ENC. For the string-based
|
||||||
|
|
Loading…
Reference in New Issue