From 31e817385d3571e4bbbf10d2596a583daf016a68 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Mon, 9 Jan 2023 06:18:58 +0900 Subject: [PATCH] Percent-encode slug in Blog::slug() --- plume-models/src/blogs.rs | 4 ++-- src/routes/blogs.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plume-models/src/blogs.rs b/plume-models/src/blogs.rs index 605d9da6..a43b1eb5 100644 --- a/plume-models/src/blogs.rs +++ b/plume-models/src/blogs.rs @@ -102,8 +102,8 @@ impl Blog { find_by!(blogs, find_by_ap_url, ap_url as &str); find_by!(blogs, find_by_name, actor_id as &str, instance_id as i32); - pub fn slug(title: &str) -> &str { - title + pub fn slug(title: &str) -> String { + iri_percent_encode_seg(title) } pub fn get_instance(&self, conn: &Connection) -> Result { diff --git a/src/routes/blogs.rs b/src/routes/blogs.rs index a70e403b..86b3ba7c 100644 --- a/src/routes/blogs.rs +++ b/src/routes/blogs.rs @@ -83,7 +83,7 @@ pub struct NewBlogForm { fn valid_slug(title: &str) -> Result<(), ValidationError> { let slug = Blog::slug(title); - if slug.is_empty() || iri_reference::(slug).is_err() { + if slug.is_empty() || iri_reference::(&slug).is_err() { Err(ValidationError::new("empty_slug")) } else { Ok(()) @@ -104,7 +104,7 @@ pub fn create( Ok(_) => ValidationErrors::new(), Err(e) => e, }; - if Blog::find_by_fqn(&conn, slug).is_ok() { + if Blog::find_by_fqn(&conn, &slug).is_ok() { errors.add( "title", ValidationError { @@ -125,7 +125,7 @@ pub fn create( let blog = Blog::insert( &conn, NewBlog::new_local( - slug.into(), + slug.clone(), form.title.to_string(), String::from(""), Instance::get_local() @@ -147,7 +147,7 @@ pub fn create( .expect("blog::create: author error"); Flash::success( - Redirect::to(uri!(details: name = slug, page = _)), + Redirect::to(uri!(details: name = &slug, page = _)), &i18n!(intl, "Your blog was successfully created!"), ) .into()