add: parse_underline, parse_comment, parse_image_size
This commit is contained in:
parent
f8dac8f491
commit
d8167aa06f
6 changed files with 275 additions and 4 deletions
|
@ -23,6 +23,8 @@ use tetratto_shared::{
|
|||
unix_epoch_timestamp,
|
||||
};
|
||||
|
||||
pub const NAME_REGEX: &str = r"[^\w_\-\.,!]+";
|
||||
|
||||
pub fn routes() -> Router {
|
||||
Router::new()
|
||||
.nest_service(
|
||||
|
@ -269,6 +271,16 @@ async fn create_request(
|
|||
return Json(Error::DataTooLong("content".to_string()).into());
|
||||
}
|
||||
|
||||
// check slug
|
||||
let regex = regex::RegexBuilder::new(NAME_REGEX)
|
||||
.multi_line(true)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
if regex.captures(&req.slug).is_some() {
|
||||
return Json(Error::MiscError("This slug contains invalid characters".to_string()).into());
|
||||
}
|
||||
|
||||
// check metadata
|
||||
let metadata: EntryMetadata = match toml::from_str(&EntryMetadata::ini_to_toml(&req.metadata)) {
|
||||
Ok(x) => x,
|
||||
|
@ -428,6 +440,18 @@ async fn edit_request(
|
|||
return Json(Error::DataTooLong("slug".to_string()).into());
|
||||
}
|
||||
|
||||
// check slug
|
||||
let regex = regex::RegexBuilder::new(NAME_REGEX)
|
||||
.multi_line(true)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
if regex.captures(&new_slug).is_some() {
|
||||
return Json(
|
||||
Error::MiscError("This slug contains invalid characters".to_string()).into(),
|
||||
);
|
||||
}
|
||||
|
||||
// check for existing
|
||||
if data
|
||||
.query(&SimplifiedQuery {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue