fix(sqlite): don't panic building URL for in-memory connect options#4329
Open
chatman-media wants to merge 1 commit into
Open
fix(sqlite): don't panic building URL for in-memory connect options#4329chatman-media wants to merge 1 commit into
chatman-media wants to merge 1 commit into
Conversation
build_url() percent-encodes the filename with a set that leaves ':' alone, so in-memory options (filename `:memory:` or the generated `file:sqlx-in-memory-N`) produce something like `sqlite://file:sqlx-in-memory-0`. The url crate reads that as a host:port authority and blows up with InvalidPort/EmptyHost instead of returning a URL. Encoding ':' too fixes it without touching how normal file paths get encoded.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SqliteConnectOptions::to_url_lossy()panics for in-memory databases. The filename for an in-memory DB is either:memory:(the default) or the generatedfile:sqlx-in-memory-N, andbuild_url()'s percent-encode set doesn't touch:, so it ends up embedding a raw colon right aftersqlite://. Theurlcrate then reads that as ahost:portauthority instead of a path and dies withInvalidPort(orEmptyHostfor the plain:memory:case).Fixed by adding
:to the encode set used when building the URL — it's not part of the WHATWG path-percent-encode-set this was modeled on, but it needs to go since it's ambiguous with authority syntax right after the scheme. Doesn't affect normal file paths since those don't have a leading colon problem. Added a test that hits both the:memory:default and thefile:sqlx-in-memory-Npath, confirmed it panics on main and passes with the fix.Closes #4327