db commands hand psql the user and password still percent encoded
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
Research direction
Start in lib/hanami/cli/commands/app/db/utils/postgres.rb at cli_env_vars, then reproduce with the DATABASE_URL and bundle exec hanami db create command from the issue. Done means PGUSER and PGPASSWORD contain decoded credentials and the database commands authenticate successfully.
Written by the indexing model from the issue text.
Description
Describe the bug
Utils::Postgres#cli_env_vars copies URI#user and URI#password into PGUSER and PGPASSWORD as they stand. Ruby's URI leaves them percent encoded, so a user or password that holds @, :, /, #, %, + or a space reaches psql, createdb, dropdb and pg_dump in its encoded form, and Postgres refuses the login.
Sequel decodes the same URL, so the app itself connects. Only the hanami db commands fail.
To Reproduce
- Create a Postgres role whose password is
p@ss:w/0rd. - Set
DATABASE_URL=postgres://app:p%40ss%3Aw%2F0rd@localhost/app_development. - Run
bundle exec hanami db create.
The existence check fails with password authentication failed for user "app", because psql sent p%40ss%3Aw%2F0rd.
The URL parses as follows:
require "uri"
uri = URI("postgres://app:p%40ss%3Aw%2F0rd@localhost/app_development")
uri.password # => "p%40ss%3Aw%2F0rd"
URI.decode_uri_component(uri.password) # => "p@ss:w/0rd"
Expected behavior
PGUSER and PGPASSWORD hold the decoded values, the same ones Sequel logs in with. Running the user and password through URI.decode_uri_component in cli_env_vars would do it.
My environment
- Ruby version: 4.0.6
- hanami-cli: 3.0.0
- Sequel: 5.108.0
- OS: macOS 27
- Dominant language
- Ruby
- Stars
- 33
- Forks
- 55
- Avg merge
- 4d 7h
- Merged PRs (30d)
- 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from hanami/hanami-cli
-
MariaDB support Open
Difficulty 5/5 Over a week Newbie friendliness 35/100
hanami/hanami-cli#448 · 3 comments ·
-
bug help wanted
Difficulty 3/5 1-2 days Newbie friendliness 55/100
hanami/hanami-cli#438 · 3 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 65/100
hanami/hanami-cli#418 ·
-
JRuby support Open
Difficulty 5/5 Over a week Newbie friendliness 35/100
hanami/hanami-cli#411 ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
hanami/hanami-cli#398 ·
All issues in hanami/hanami-cli
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
resque/resque-scheduler#826 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
googleapis/google-api-ruby-client#28001 · 5 reactions ·