Skip to content

Decode percent-encoded user/password in connection_url - #451

Open
hikmetba-bit wants to merge 1 commit into
que-rb:masterfrom
hikmetba-bit:fix/decode-connection-url-credentials-436
Open

hikmetba-bit wants to merge 1 commit into
que-rb:masterfrom
hikmetba-bit:fix/decode-connection-url-credentials-436

Conversation

@hikmetba-bit

Copy link
Copy Markdown

Summary

Fixes #436.

Locker#work parses the connection_url option with URI.parse, then passes uri.user/uri.password straight through to PG::Connection.open. URI#user and URI#password return the raw percent-encoded component, so a password containing characters that require URL-escaping (e.g. p%40ss%3Aword for p@ss:word) was handed to PG::Connection.open still escaped, causing authentication to fail — exactly the failure reported in the issue.

Fix

Decode both user and password with URI.decode_www_form_component before building the connection opts (nil-guarded, so a URL with no credentials still works).

Verification

Ran the exact parsing logic in isolation against 4 cases:

postgres://myuser:p%40ss%3Aword@localhost:5432/mydb  -> password: "p@ss:word"   (was "p%40ss%3Aword" before the fix)
postgres://myuser:plainpass@localhost:5432/mydb      -> password: "plainpass"   (unchanged, not double-processed)
postgres://myuser@localhost:5432/mydb                -> password: nil           (no crash on nil)
postgres://my%40user:pass@localhost:5432/mydb        -> user: "my@user"         (username decoding also fixed)

I could not run que's full locker integration spec suite in this environment since it requires a live PostgreSQL instance to connect against — flagging that honestly. The change itself is a 2-line, narrowly-scoped fix isolated to how the two URI components are read, with no other code path affected.

🤖 Generated with Claude Code

Locker#work parses the connection_url option with URI.parse, then
passes uri.user/uri.password straight through to PG::Connection.open.
URI#user and URI#password return the RAW percent-encoded component,
so a password containing characters that require URL-escaping (e.g.
'p%40ss%3Aword' for 'p@ss:word') was handed to PG::Connection.open
still escaped, causing authentication to fail.

Decode both with URI.decode_www_form_component before building the
connection opts, guarding against nil so a URL with no user/password
still works.

Fixes que-rb#436.
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-url doesn't handle URI-encoded password

1 participant