fix(core): encode postgres usernames in connection urls#40
Conversation
Encode saved Postgres usernames when building runtime connection URLs and decode usernames imported from pasted URLs. This keeps `@` from breaking URI parsing while preserving literal percent sequences.
There was a problem hiding this comment.
Pull request overview
This PR fixes Postgres connection URL handling by percent-encoding usernames when generating URLs and decoding percent-encoded usernames when parsing/pasting URLs, including correct handling of literal percent sequences (e.g., user%40team).
Changes:
- Percent-encode Postgres usernames in
ConnectionEntry::to_url(). - Percent-decode usernames in
ConnectionEntry::from_url()(used by URL paste/import flows). - Add regression tests for
@in usernames and literal percent round-tripping, plus a UI URL-paste test.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/tsql/src/config/connections.rs | Encode usernames in generated Postgres URLs; decode usernames when parsing URLs; add targeted tests for encoding/decoding and literal % preservation. |
| crates/tsql/src/ui/connection_form.rs | Add test ensuring URL paste correctly decodes a percent-encoded Postgres username. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Add user | ||
| url.push_str(&self.user); | ||
| url.push_str(&urlencoding::encode(&self.user)); | ||
|
|
||
| // Add password if provided |
There was a problem hiding this comment.
to_url() now uses the local urlencoding helper for usernames as well as passwords, but the helper is scoped/named/documented as password-specific (see mod urlencoding comment later in this file). Consider renaming/updating the helper (or its doc comment) to reflect that it encodes general userinfo components, to avoid future confusion/misuse.
Fixes #33.
Supersedes #34.
Summary
user%40teamVerification
cargo test -p tsql --lib connection_to_urlcargo test -p tsql --lib connection_from_urlcargo test -p tsql --lib url_pastecargo fmt --allcargo clippy --all --all-targets -- -D warningscargo test --lib --bins