fix(prns): url encode unicode

This commit is contained in:
sam 2023-08-12 15:00:26 +02:00
parent ccd546759b
commit cd3e4ef6c5
No known key found for this signature in database
GPG key ID: B4EF20DDE721CAA1
9 changed files with 17 additions and 8 deletions

11
Cargo.lock generated
View file

@ -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"

View file

@ -1,5 +1,5 @@
[workspace]
members = [
"pronouns",
"pronounslib",
"prns",
]

View file

@ -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"

View file

@ -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<AppState>, 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<AppState>, path: PathBuf) -> Redirect {
|u| {
Redirect::temporary(format!(
"{}/@{}/{}",
state.base_url, u.username, member.name
state.base_url, encode(&u.username), encode(&member.name)
))
},
)

View file

@ -1,5 +1,5 @@
[package]
name = "pronouns"
name = "pronounslib"
version = "0.1.0"
edition = "2021"