mirror of
https://github.com/micropython/micropython.git
synced 2026-01-04 11:10:14 +01:00
py/objarray: Detect bytearray(str) without an encoding.
This prevents a very subtle bug caused by writing e.g. `bytearray('\xfd')`
which gives you `(0xc3, 0xbd)`.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
committed by
Damien George
parent
f8b0ae32d3
commit
2c8dab7ab4
@@ -233,7 +233,11 @@ STATIC mp_obj_t bytes_make_new(const mp_obj_type_t *type_in, size_t n_args, size
|
||||
|
||||
if (mp_obj_is_str(args[0])) {
|
||||
if (n_args < 2 || n_args > 3) {
|
||||
#if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE
|
||||
goto wrong_args;
|
||||
#else
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("string argument without an encoding"));
|
||||
#endif
|
||||
}
|
||||
GET_STR_DATA_LEN(args[0], str_data, str_len);
|
||||
GET_STR_HASH(args[0], str_hash);
|
||||
|
||||
Reference in New Issue
Block a user