|
1 |
| -# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
| 1 | +# Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. |
2 | 2 | # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
3 | 3 | #
|
4 | 4 | # The Universal Permissive License (UPL), Version 1.0
|
@@ -311,3 +311,28 @@ def __getitem__(self, key):
|
311 | 311 | exec("global x; x = y", ns, m)
|
312 | 312 | assert ns["x"] == "y";
|
313 | 313 | assert eval("x", None, m) == "x"
|
| 314 | + |
| 315 | + def test_exec_encoding(self): |
| 316 | + x = {} |
| 317 | + exec(b'#!/usr/bin/python\n# vim:fileencoding=cp1250\nx = "\x9elu\x9dou\xe8k\xfd k\xf9\xf2"', x) |
| 318 | + assert x['x'] == 'žluťoučký kůň' |
| 319 | + |
| 320 | + def test_exec_invalid_encoding(self): |
| 321 | + def fn(): |
| 322 | + exec(b'# encoding: cp12413254\nx=1') |
| 323 | + raises(SyntaxError, fn) |
| 324 | + |
| 325 | + def test_exec_ignore_decoded(self): |
| 326 | + x = {} |
| 327 | + exec('# encoding: cp12413254\nx=1', x) |
| 328 | + assert x['x'] == 1 |
| 329 | + |
| 330 | + def test_exec_bom(self): |
| 331 | + x = {} |
| 332 | + exec(b'\xef\xbb\xbfx = "\xe6\xa5\xbd\xe3\x81\x97\xe3\x81\x84"', x) |
| 333 | + assert x['x'] == '楽しい' |
| 334 | + |
| 335 | + def test_exec_bom_invalid(self): |
| 336 | + def fn(): |
| 337 | + exec(b'\xef\xbb\xbf#encoding:latin-1\nx = "\xe9\xa7\x84\xe7\x9b\xae"') |
| 338 | + raises(SyntaxError, fn) |
0 commit comments