From 82eb997e2df6a6590c8405be7eee43d39dcf8f34 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 15 Jun 2020 14:42:02 +0200 Subject: [PATCH] Remove HTML code of conversation names --- src/controllers/conversations_controller.rs | 14 +++++++------- src/utils/mod.rs | 3 ++- src/utils/string_utils.rs | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 src/utils/string_utils.rs diff --git a/src/controllers/conversations_controller.rs b/src/controllers/conversations_controller.rs index c2de980..847f273 100644 --- a/src/controllers/conversations_controller.rs +++ b/src/controllers/conversations_controller.rs @@ -2,12 +2,13 @@ //! //! @author Pierre Hubert -use crate::data::http_request_handler::HttpRequestHandler; -use crate::controllers::routes::RequestResult; -use crate::helpers::{user_helper, conversations_helper}; -use crate::data::new_conversation::NewConversation; -use crate::api_data::res_create_conversation::ResCreateConversation; use crate::api_data::conversation_api::ConversationAPI; +use crate::api_data::res_create_conversation::ResCreateConversation; +use crate::controllers::routes::RequestResult; +use crate::data::http_request_handler::HttpRequestHandler; +use crate::data::new_conversation::NewConversation; +use crate::helpers::{conversations_helper, user_helper}; +use crate::utils::string_utils::remove_html_nodes; /// Create a new conversation pub fn create(r: &mut HttpRequestHandler) -> RequestResult { @@ -110,8 +111,7 @@ pub fn update_settings(r: &mut HttpRequestHandler) -> RequestResult { let name = if name.eq("false") || name.is_empty() { None } else { - // TODO : remove HTML nodes - Some(name) + Some(remove_html_nodes(&name)) }; conversations_helper::set_name(conv_id, name)?; diff --git a/src/utils/mod.rs b/src/utils/mod.rs index a4298ea..bda5ce1 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -5,4 +5,5 @@ pub mod crypt_utils; pub mod user_data_utils; pub mod virtual_directories_utils; -pub mod date_utils; \ No newline at end of file +pub mod date_utils; +pub mod string_utils; \ No newline at end of file diff --git a/src/utils/string_utils.rs b/src/utils/string_utils.rs new file mode 100644 index 0000000..10d3e08 --- /dev/null +++ b/src/utils/string_utils.rs @@ -0,0 +1,19 @@ +//! # String utilities +//! +//! This module contains utilities that can be used accross all the application + +/// Escape an HTML string +/// +/// Removes the HTML code included inside a string +/// +/// ``` +/// use comunic_server::utils::string_utils::remove_html_nodes; +/// +/// let s1 = "hello world"; +/// let res1 = remove_html_nodes(s1); +/// assert_eq!(res1, "<b>hello world</b>"); +/// ``` +pub fn remove_html_nodes(input: &str) -> String { + input.replace("<", "<") + .replace(">", ">") +} \ No newline at end of file