Skip to content

Commit d42e8f0

Browse files
authored
fix(sqlite): produce correct error for surrogate characters (#5962)
1 parent ed8d715 commit d42e8f0

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

Lib/test/test_sqlite3/test_userfunctions.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,6 @@ def test_return_non_contiguous_blob(self):
354354
cur = self.con.execute("select return_noncont_blob()")
355355
cur.fetchone()
356356

357-
# TODO: RUSTPYTHON
358-
@unittest.expectedFailure
359357
def test_param_surrogates(self):
360358
self.assertRaisesRegex(UnicodeEncodeError, "surrogates not allowed",
361359
self.con.execute, "select spam(?)",

stdlib/src/sqlite.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2965,12 +2965,10 @@ mod _sqlite {
29652965
}
29662966

29672967
fn str_to_ptr_len(s: &PyStr, vm: &VirtualMachine) -> PyResult<(*const libc::c_char, i32)> {
2968-
let s = s
2969-
.to_str()
2970-
.ok_or_else(|| vm.new_unicode_encode_error("surrogates not allowed"))?;
2971-
let len = c_int::try_from(s.len())
2968+
let s_str = s.try_to_str(vm)?;
2969+
let len = c_int::try_from(s_str.len())
29722970
.map_err(|_| vm.new_overflow_error("TEXT longer than INT_MAX bytes"))?;
2973-
let ptr = s.as_ptr().cast();
2971+
let ptr = s_str.as_ptr().cast();
29742972
Ok((ptr, len))
29752973
}
29762974

0 commit comments

Comments
 (0)