Skip to content

Commit

Permalink
Fix db console for password/username/database with special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasKalbertodt committed Aug 8, 2022
1 parent ef6ea6a commit 3e04c50
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ p256 = { version = "0.11", features = ["jwk"] }
p384 = { version = "0.11", features = ["jwk"] }
paste = "1"
pem = "1"
percent-encoding = "2.1.0"
postgres-types = { version = "0.2.2", features = ["derive", "array-impls"] }
rand = "0.8.4"
reinda = "0.2"
Expand Down
8 changes: 5 additions & 3 deletions backend/src/db/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,15 @@ async fn run_script(db: &Db, script_path: &Path) -> Result<()> {
}

fn console(config: &DbConfig) -> Result<Never> {
let encode = |s| percent_encoding::utf8_percent_encode(s, percent_encoding::NON_ALPHANUMERIC);

let connection_uri = format!(
"postgresql://{}:{}@{}:{}/{}",
config.user,
config.password.expose_secret(),
encode(&config.user),
encode(&config.password.expose_secret()),
config.host,
config.port,
config.database,
encode(&config.database),
);
let error = Command::new("psql").arg(connection_uri).exec();
let message = match error.kind() {
Expand Down

0 comments on commit 3e04c50

Please sign in to comment.