◐ Shell
clean mode source ↗

Raise `ValueError` if `\x00` character exists for `eval` argument by moreal · Pull Request #4052 · RustPython/RustPython

what happens if bytes include invalid utf8 character?

It causes panic. I tested with the below python code:

And it prints:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Utf8Error { valid_up_to: 0, error_len: Some(1) }', vm/src/stdlib/builtins.rs:268:64
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Because the C language const char * type for string and also byte array, it can be represented as a single type with a compiler option. So I'll see more the compiler, parser section. If you have useful documentations to recommend, please leave them as comments 🙇🏻‍♂️

// _PyPegen_run_parser_from_string
    if (flags != NULL && flags->cf_flags & PyCF_IGNORE_COOKIE) {
        tok = PyTokenizer_FromUTF8(str, exec_input);
    } else {
        tok = PyTokenizer_FromString(str, exec_input);
    }