Skip to content

Commit 5c81649

Browse files
authored
Return SyntaxError with null byte input in eval. (RustPython#5013)
* Return SyntaxError with null byte input in eval. * Special case MacOS for now, add a note for future sanity.
1 parent d64d33c commit 5c81649

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

extra_tests/snippets/syntax_non_utf8.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55

66
dir_path = os.path.dirname(os.path.realpath(__file__))
77

8-
with assert_raises(ValueError):
8+
# TODO: RUSTPYTHON. At some point snippets will fail and it will look confusing
9+
# and out of the blue. This is going to be the cause and it's going to happen when
10+
# the github worker for MacOS starts using Python 3.11.4.
11+
if platform.python_implementation == "CPython" and platform.system() == 'Darwin':
12+
expectedException = ValueError
13+
else:
14+
expectedException = SyntaxError
15+
16+
with assert_raises(expectedException):
917
with open(os.path.join(dir_path , "non_utf8.txt")) as f:
1018
eval(f.read())

vm/src/stdlib/builtins.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ mod builtins {
257257
Either::A(either) => {
258258
let source: &[u8] = &either.borrow_bytes();
259259
if source.contains(&0) {
260-
return Err(vm.new_value_error(
260+
return Err(vm.new_exception_msg(
261+
vm.ctx.exceptions.syntax_error.to_owned(),
261262
"source code string cannot contain null bytes".to_owned(),
262263
));
263264
}

0 commit comments

Comments
 (0)