Percent-encode slug in Blog::slug()

This commit is contained in:
Kitaiti Makoto 2023-01-09 06:18:58 +09:00
parent af7ed450e2
commit 31e817385d
2 changed files with 6 additions and 6 deletions

View file

@ -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<Instance> {

View file

@ -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::<IriSpec>(slug).is_err() {
if slug.is_empty() || iri_reference::<IriSpec>(&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()