diff options
author | Vincent Ambo <tazjin@gmail.com> | 2018-04-15T10·59+0200 |
---|---|---|
committer | Vincent Ambo <tazjin@gmail.com> | 2018-04-15T11·01+0200 |
commit | aeaa497a621a132e4bbc4ab6fb766473621196b7 (patch) | |
tree | c002193253a27648621c7023ae679b0dfc3586c5 | |
parent | ee4b690d22050b790d161ea943baf87f6f20a256 (diff) |
fix(handlers): Trim leading/trailing whitespace from new threads
-rw-r--r-- | src/handlers.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/handlers.rs b/src/handlers.rs index f4346f26c6c3..1cd596aad1d2 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -109,13 +109,19 @@ const NEW_THREAD_LENGTH_ERR: &'static str = "Title and body can not be empty!"; pub fn submit_thread(state: State<AppState>, input: Form<NewThreadForm>, mut req: HttpRequest<AppState>) -> ConverseResponse { + // Trim whitespace out of inputs: + let input = NewThreadForm { + title: input.title.trim().into(), + body: input.body.trim().into(), + }; + // Perform simple validation and abort here if it fails: - if input.0.title.is_empty() || input.0.body.is_empty() { + if input.title.is_empty() || input.body.is_empty() { return state.renderer .send(NewThreadPage { alerts: vec![NEW_THREAD_LENGTH_ERR], - title: Some(input.0.title), - body: Some(input.0.body), + title: Some(input.title), + body: Some(input.body), }) .flatten() .map(|res| HttpResponse::Ok().content_type(HTML).body(res)) @@ -127,14 +133,14 @@ pub fn submit_thread(state: State<AppState>, .unwrap_or_else(anonymous); let new_thread = NewThread { - title: input.0.title, + title: input.title, author_name: author.name, author_email: author.email, }; let msg = CreateThread { new_thread, - body: input.0.body, + body: input.body, }; state.db.send(msg) @@ -166,7 +172,7 @@ pub fn reply_thread(state: State<AppState>, let new_post = NewPost { thread_id: input.thread_id, - body: input.0.body, + body: input.body.trim().into(), author_name: author.name, author_email: author.email, }; |