From ceae0f5993a51cca1122128aeaa16a4db35533af Mon Sep 17 00:00:00 2001 From: Nutomic Date: Tue, 8 Nov 2022 02:29:32 +0000 Subject: [PATCH] Use urlencoding for db url params (fixes #2532) (#2537) --- Cargo.lock | 1 + config/config.hjson | 4 ++++ crates/utils/Cargo.toml | 1 + crates/utils/src/settings/mod.rs | 7 ++++++- 4 files changed, 12 insertions(+), 1 deletion(-) 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), ) } -- 2.44.1