summaryrefslogtreecommitdiff
path: root/py/objstr.c
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2022-08-26 12:54:53 +1000
committerDamien George <damien@micropython.org>2022-08-26 16:44:20 +1000
commit88864587f5af292d7f86aceb6bf40e8331e9a8d6 (patch)
tree324316dfa37f289185d80d6a82048f8fba823e73 /py/objstr.c
parent8a0ee5a5c04e83f04d1c62029ac5ba7c74856507 (diff)
py/objstr: Always ensure mp_obj_str_from_vstr is unicode-safe.
Now that we have `mp_obj_new_str_type_from_vstr` (private helper used by objstr.c) split from the public API (`mp_obj_new_str_from_vstr`), we can enforce a unicode check at the public API without incurring a performance cost on the various objstr.c methods (which are already working on known unicode-safe strings). Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'py/objstr.c')
-rw-r--r--py/objstr.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/py/objstr.c b/py/objstr.c
index 69745a2f5..ab1229ad6 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -2248,6 +2248,11 @@ STATIC mp_obj_t mp_obj_new_str_type_from_vstr(const mp_obj_type_t *type, vstr_t
}
mp_obj_t mp_obj_new_str_from_vstr(vstr_t *vstr) {
+ #if MICROPY_PY_BUILTINS_STR_UNICODE && MICROPY_PY_BUILTINS_STR_UNICODE_CHECK
+ if (!utf8_check((byte *)vstr->buf, vstr->len)) {
+ mp_raise_msg(&mp_type_UnicodeError, NULL);
+ }
+ #endif // MICROPY_PY_BUILTINS_STR_UNICODE && MICROPY_PY_BUILTINS_STR_UNICODE_CHECK
return mp_obj_new_str_type_from_vstr(&mp_type_str, vstr);
}