Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Lib/test/test_sqlite3/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,6 @@ def test_null_character(self):
self.assertRaisesRegex(sqlite.ProgrammingError, "null char",
cur.execute, query)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_surrogates(self):
con = sqlite.connect(":memory:")
self.assertRaises(UnicodeEncodeError, con, "select '\ud8ff'")
Expand Down
1 change: 1 addition & 0 deletions stdlib/src/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2294,6 +2294,7 @@ mod _sqlite {
sql: &PyStr,
vm: &VirtualMachine,
) -> PyResult<Option<Self>> {
let _ = sql.try_to_str(vm)?;
let sql_cstr = sql.to_cstring(vm)?;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means we shouldn't create cstring from wtf8, but have to create one from str.
The underlying logic of this approach is fine. But let _ = sql.try_to_str(vm)?; to discard the result of try_to_str is weird.
How about adding a new helper method, fn ensure_utf8(&self) -> PyResult<()>, which provides basically the same feature but with better naming? I can call try_to_str inside.

Another suggestion is a proper way to handle it.

impl PyRef<PyStr> {
...
    fn into_utf8(self) -> PyRef<PyUtf8Str>
...
}

struct PyUtf8Str(PyStr);

This will be useful when we actually need utf8 string instead of wtf8

let sql_len = sql.byte_len() + 1;

Expand Down
Loading