fix(sqlite): produce correct error for surrogate characters (#5962)

This commit is contained in:
Jiseok CHOI authored and GitHub committed 2025-07-14 14:21:36 +09:00
1 parent ed8d7157d9
commit d42e8f0042
2 files changed
+3 -7

No files matched your search

-2
View File
@@ -354,8 +354,6 @@ class FunctionTests(unittest.TestCase):
cur = self.con.execute("select return_noncont_blob()")
cur.fetchone()
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_param_surrogates(self):
self.assertRaisesRegex(UnicodeEncodeError, "surrogates not allowed",
self.con.execute, "select spam(?)",
+3 -5
View File
@@ -2965,12 +2965,10 @@ mod _sqlite {
}
fn str_to_ptr_len(s: &PyStr, vm: &VirtualMachine) -> PyResult<(*const libc::c_char, i32)> {
let s = s
.to_str()
.ok_or_else(|| vm.new_unicode_encode_error("surrogates not allowed"))?;
let len = c_int::try_from(s.len())
let s_str = s.try_to_str(vm)?;
let len = c_int::try_from(s_str.len())
.map_err(|_| vm.new_overflow_error("TEXT longer than INT_MAX bytes"))?;
let ptr = s.as_ptr().cast();
let ptr = s_str.as_ptr().cast();
Ok((ptr, len))
}