Skip to content

fix(core): encode postgres usernames in connection urls#40

Merged
fcoury merged 1 commit intomasterfrom
fix/postgres-username-url-encoding
Apr 18, 2026
Merged

fix(core): encode postgres usernames in connection urls#40
fcoury merged 1 commit intomasterfrom
fix/postgres-username-url-encoding

Conversation

@fcoury
Copy link
Copy Markdown
Owner

@fcoury fcoury commented Apr 18, 2026

Fixes #33.
Supersedes #34.

Summary

  • encode saved Postgres usernames when building connection URLs
  • decode percent-encoded usernames when importing/pasting Postgres URLs
  • preserve literal percent sequences such as user%40team

Verification

  • cargo test -p tsql --lib connection_to_url
  • cargo test -p tsql --lib connection_from_url
  • cargo test -p tsql --lib url_paste
  • cargo fmt --all
  • cargo clippy --all --all-targets -- -D warnings
  • cargo test --lib --bins

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.
Copilot AI review requested due to automatic review settings April 18, 2026 19:34
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines 278 to 281
// Add user
url.push_str(&self.user);
url.push_str(&urlencoding::encode(&self.user));

// Add password if provided
Copy link

Copilot AI Apr 18, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@fcoury fcoury merged commit 410dd18 into master Apr 18, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Connection manager: Postgres usernames are not encoded and can break the connection URI

2 participants