Use urlencoding for db url params (fixes #2532) (#2537)

This commit is contained in:
Nutomic 2022-11-08 02:29:32 +00:00 committed by GitHub
parent a0a84d91ce
commit ceae0f5993
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 1 deletions

1
Cargo.lock generated
View file

@ -2225,6 +2225,7 @@ dependencies = [
"once_cell", "once_cell",
"openssl", "openssl",
"parking_lot", "parking_lot",
"percent-encoding",
"rand 0.8.5", "rand 0.8.5",
"regex", "regex",
"reqwest-middleware", "reqwest-middleware",

View file

@ -2,4 +2,8 @@
# https://join-lemmy.org/docs/en/administration/configuration.html # https://join-lemmy.org/docs/en/administration/configuration.html
{ {
hostname: lemmy-alpha hostname: lemmy-alpha
database: {
# Username to connect to postgres
user: "&££%^!£*!:::!"£:!:"
}
} }

View file

@ -44,6 +44,7 @@ html2text = "0.4.2"
rosetta-i18n = "0.1.2" rosetta-i18n = "0.1.2"
parking_lot = "0.12.1" parking_lot = "0.12.1"
typed-builder = "0.10.0" typed-builder = "0.10.0"
percent-encoding = "2.2.0"
[build-dependencies] [build-dependencies]
rosetta-build = "0.1.2" rosetta-build = "0.1.2"

View file

@ -6,6 +6,7 @@ use crate::{
use anyhow::{anyhow, Context}; use anyhow::{anyhow, Context};
use deser_hjson::from_str; use deser_hjson::from_str;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
use regex::Regex; use regex::Regex;
use std::{env, fs, io::Error}; use std::{env, fs, io::Error};
@ -44,7 +45,11 @@ impl Settings {
let conf = &self.database; let conf = &self.database;
format!( format!(
"postgres://{}:{}@{}:{}/{}", "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),
) )
} }