From cd3e4ef6c574f13c7b60ce4f95893498c178073d Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 12 Aug 2023 15:00:26 +0200 Subject: [PATCH] fix(prns): url encode unicode --- Cargo.lock | 11 +++++++++-- Cargo.toml | 2 +- prns/Cargo.toml | 3 ++- prns/src/main.rs | 7 ++++--- {pronouns => pronounslib}/Cargo.toml | 2 +- {pronouns => pronounslib}/src/lib.rs | 0 {pronouns => pronounslib}/src/models.rs | 0 {pronouns => pronounslib}/src/models/member.rs | 0 {pronouns => pronounslib}/src/models/user.rs | 0 9 files changed, 17 insertions(+), 8 deletions(-) rename {pronouns => pronounslib}/Cargo.toml (94%) rename {pronouns => pronounslib}/src/lib.rs (100%) rename {pronouns => pronounslib}/src/models.rs (100%) rename {pronouns => pronounslib}/src/models/member.rs (100%) rename {pronouns => pronounslib}/src/models/user.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 4ace77f..4df9730 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1003,12 +1003,13 @@ version = "0.1.0" dependencies = [ "dotenvy", "log", - "pronouns", + "pronounslib", "rocket", "simple_logger", "sqlx", "time", "tokio", + "urlencoding", ] [[package]] @@ -1034,7 +1035,7 @@ dependencies = [ ] [[package]] -name = "pronouns" +name = "pronounslib" version = "0.1.0" dependencies = [ "serde", @@ -1971,6 +1972,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "urlencoding" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" + [[package]] name = "valuable" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index fd18838..4494d47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] members = [ - "pronouns", + "pronounslib", "prns", ] diff --git a/prns/Cargo.toml b/prns/Cargo.toml index 16620f9..e03a2e0 100644 --- a/prns/Cargo.toml +++ b/prns/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -pronouns = { path = "../pronouns" } +pronounslib = { path = "../pronounslib" } time = { version = "0.3.23", features = ["formatting", "serde"] } sqlx = { version = "0.6.3", features = ["runtime-tokio-rustls", "postgres", "json"]} rocket = "0.5.0-rc.3" @@ -14,3 +14,4 @@ tokio = { version = "1.27.0", features = ["full"] } dotenvy = "0.15.7" simple_logger = "4.2.0" log = "0.4.19" +urlencoding = "2.1.3" diff --git a/prns/src/main.rs b/prns/src/main.rs index a8b6c24..b1f8303 100644 --- a/prns/src/main.rs +++ b/prns/src/main.rs @@ -1,10 +1,11 @@ pub mod models; +use crate::models::{Member, User}; use rocket::{response::Redirect, Config, State}; use simple_logger; use sqlx::{postgres::PgPoolOptions, Pool, Postgres}; use std::{env, path::PathBuf}; -use crate::models::{User, Member}; +use urlencoding::encode; #[macro_use] extern crate rocket; @@ -27,7 +28,7 @@ async fn redirect(state: &State, path: PathBuf) -> Redirect { .await .map_or_else( |_| Redirect::temporary(state.base_url.clone()), - |u| Redirect::temporary(format!("{}/@{}", state.base_url, u.username)), + |u| Redirect::temporary(format!("{}/@{}", state.base_url, encode(&u.username))), ), 6 => { let member = match sqlx::query_as!( @@ -54,7 +55,7 @@ async fn redirect(state: &State, path: PathBuf) -> Redirect { |u| { Redirect::temporary(format!( "{}/@{}/{}", - state.base_url, u.username, member.name + state.base_url, encode(&u.username), encode(&member.name) )) }, ) diff --git a/pronouns/Cargo.toml b/pronounslib/Cargo.toml similarity index 94% rename from pronouns/Cargo.toml rename to pronounslib/Cargo.toml index 3649845..e3c4556 100644 --- a/pronouns/Cargo.toml +++ b/pronounslib/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "pronouns" +name = "pronounslib" version = "0.1.0" edition = "2021" diff --git a/pronouns/src/lib.rs b/pronounslib/src/lib.rs similarity index 100% rename from pronouns/src/lib.rs rename to pronounslib/src/lib.rs diff --git a/pronouns/src/models.rs b/pronounslib/src/models.rs similarity index 100% rename from pronouns/src/models.rs rename to pronounslib/src/models.rs diff --git a/pronouns/src/models/member.rs b/pronounslib/src/models/member.rs similarity index 100% rename from pronouns/src/models/member.rs rename to pronounslib/src/models/member.rs diff --git a/pronouns/src/models/user.rs b/pronounslib/src/models/user.rs similarity index 100% rename from pronouns/src/models/user.rs rename to pronounslib/src/models/user.rs