]> Untitled Git - lemmy.git/commitdiff
Use urlencoding for db url params (fixes #2532) (#2537)
authorNutomic <me@nutomic.com>
Tue, 8 Nov 2022 02:29:32 +0000 (02:29 +0000)
committerGitHub <noreply@github.com>
Tue, 8 Nov 2022 02:29:32 +0000 (21:29 -0500)
Cargo.lock
config/config.hjson
crates/utils/Cargo.toml
crates/utils/src/settings/mod.rs

index 20e6c85be15b7bb132b7863d80553fc913f4c31e..8d50197bd7cde705a0df45ef42a79a8c7cb7a9c4 100644 (file)
@@ -2225,6 +2225,7 @@ dependencies = [
  "once_cell",
  "openssl",
  "parking_lot",
+ "percent-encoding",
  "rand 0.8.5",
  "regex",
  "reqwest-middleware",
index 252fca25044f07c0075e52174f23c88f3d37d2ce..c26e52d4f41527636f1dc410a7adabafc2243a88 100644 (file)
@@ -2,4 +2,8 @@
 # https://join-lemmy.org/docs/en/administration/configuration.html
 {
   hostname: lemmy-alpha
+  database: {
+    # Username to connect to postgres
+    user: "&££%^!£*!:::!"£:!:"
+  }
 }
index 0c8926d65fc44afffcc733a5042fd4595accdd7a..6e0fbcbd479e9beeccc91892fc4830cb08f627c6 100644 (file)
@@ -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"
index 42d571662e8b4ecf5335be06ee46807840933b9c..004f48b8636d323b3da98b3c1b1d027ce1668b5b 100644 (file)
@@ -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),
     )
   }