From 38ee726a5973a727071d1e6b1fee998d7d2f0023 Mon Sep 17 00:00:00 2001 From: SHIMIZU Toshihiro Date: Thu, 18 Mar 2021 10:54:36 +0900 Subject: [PATCH] percent encoding of passwords Signed-off-by: SHIMIZU Toshihiro --- experimental/plugins/postgres_storage/Cargo.toml | 1 + .../plugins/postgres_storage/src/postgres_storage.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/experimental/plugins/postgres_storage/Cargo.toml b/experimental/plugins/postgres_storage/Cargo.toml index ad7d69339f..42ed839a1a 100644 --- a/experimental/plugins/postgres_storage/Cargo.toml +++ b/experimental/plugins/postgres_storage/Cargo.toml @@ -68,6 +68,7 @@ log-panics = "2.0.0" postgres = "0.15.2" r2d2 = "0.8.2" r2d2_postgres = "0.14.0" +percent-encoding = "2.1.0" [dependencies.uuid] version = "0.5.0" diff --git a/experimental/plugins/postgres_storage/src/postgres_storage.rs b/experimental/plugins/postgres_storage/src/postgres_storage.rs index 225f37482e..8b693d5b97 100644 --- a/experimental/plugins/postgres_storage/src/postgres_storage.rs +++ b/experimental/plugins/postgres_storage/src/postgres_storage.rs @@ -2,6 +2,7 @@ extern crate owning_ref; extern crate sodiumoxide; extern crate r2d2; extern crate r2d2_postgres; +extern crate percent_encoding; use ::std::sync::RwLock; @@ -13,6 +14,8 @@ use self::owning_ref::OwningHandle; use std::rc::Rc; use std::time::Duration; +use self::percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC}; + use errors::wallet::WalletStorageError; use errors::common::CommonError; use wql::language; @@ -1037,11 +1040,12 @@ impl PostgresStorageType { } url_base.push_str(":"); match credentials.admin_password { - Some(ref password) => url_base.push_str(&password[..]), + Some(ref password) => url_base.push_str(&utf8_percent_encode(&password[..], &NON_ALPHANUMERIC).to_string()), None => () } url_base.push_str("@"); url_base.push_str(&config.url[..]); + url_base.push_str("/postgres"); url_base } @@ -1049,7 +1053,7 @@ impl PostgresStorageType { let mut url_base = "postgresql://".to_owned(); url_base.push_str(&credentials.account[..]); url_base.push_str(":"); - url_base.push_str(&credentials.password[..]); + url_base.push_str(&utf8_percent_encode(&credentials.password[..], &NON_ALPHANUMERIC).to_string()); url_base.push_str("@"); url_base.push_str(&config.url[..]); url_base