Skip to content

gh-153731: Handle NUL and lone surrogate in sqlite3 CLI REPL#153732

Open
tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:sqlite3-cli-nul
Open

gh-153731: Handle NUL and lone surrogate in sqlite3 CLI REPL#153732
tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:sqlite3-cli-nul

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

In the python -m sqlite3 REPL, complete_statement() raises ValueError
(embedded NUL) or UnicodeEncodeError (lone surrogate), neither of which is a
sqlite3.Error, so a single such input line crashed the shell. Catch these two
and print an error, keeping the REPL running like the other error paths.

@aisk

aisk commented Jul 15, 2026

Copy link
Copy Markdown
Member

UnicodeEncodeError is actually a subclass of ValueError, so catching both is redundant.

But the main question is that ValueError is not narrow, many code paths may raise it. I think it's better to just add a pre-check to see whether \0 is in the input, and then show an error to the user.

We can also use a similar approach to check whether a lone surrogate is in the input, but I'm not an expert on Unicode, and UnicodeEncodeError is a narrow exception, so I think it's okay to keep catching it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants