From: Nutomic Date: Tue, 8 Nov 2022 02:29:32 +0000 (+0000) Subject: Use urlencoding for db url params (fixes #2532) (#2537) X-Git-Url: http://these/git/%7B%60%24%7BghostArchiveUrl%7D/static/%7Bpost_view.post.url%7D?a=commitdiff_plain;h=ceae0f5993a51cca1122128aeaa16a4db35533af;p=lemmy.git Use urlencoding for db url params (fixes #2532) (#2537) --- diff --git a/Cargo.lock b/Cargo.lock index 20e6c85b..8d50197b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2225,6 +2225,7 @@ dependencies = [ "once_cell", "openssl", "parking_lot", + "percent-encoding", "rand 0.8.5", "regex", "reqwest-middleware", diff --git a/config/config.hjson b/config/config.hjson index 252fca25..c26e52d4 100644 --- a/config/config.hjson +++ b/config/config.hjson @@ -2,4 +2,8 @@ # https://join-lemmy.org/docs/en/administration/configuration.html { hostname: lemmy-alpha + database: { + # Username to connect to postgres + user: "&££%^!£*!:::!"£:!:" + } } diff --git a/crates/utils/Cargo.toml b/crates/utils/Cargo.toml index 0c8926d6..6e0fbcbd 100644 --- a/crates/utils/Cargo.toml +++ b/crates/utils/Cargo.toml @@ -44,6 +44,7 @@ html2text = "0.4.2" rosetta-i18n = "0.1.2" parking_lot = "0.12.1" typed-builder = "0.10.0" +percent-encoding = "2.2.0" [build-dependencies] rosetta-build = "0.1.2" diff --git a/crates/utils/src/settings/mod.rs b/crates/utils/src/settings/mod.rs index 42d57166..004f48b8 100644 --- a/crates/utils/src/settings/mod.rs +++ b/crates/utils/src/settings/mod.rs @@ -6,6 +6,7 @@ use crate::{ use anyhow::{anyhow, Context}; use deser_hjson::from_str; use once_cell::sync::Lazy; +use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC}; use regex::Regex; use std::{env, fs, io::Error}; @@ -44,7 +45,11 @@ impl Settings { let conf = &self.database; format!( "postgres://{}:{}@{}:{}/{}", - conf.user, conf.password, conf.host, conf.port, conf.database, + utf8_percent_encode(&conf.user, NON_ALPHANUMERIC), + utf8_percent_encode(&conf.password, NON_ALPHANUMERIC), + conf.host, + conf.port, + utf8_percent_encode(&conf.database, NON_ALPHANUMERIC), ) }