mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-01-14 14:37:44 +00:00
Can check the validity of an URL
This commit is contained in:
parent
bd3818360b
commit
c2bac9401a
@ -2,6 +2,12 @@
|
||||
//!
|
||||
//! This module contains utilities that can be used accross all the application
|
||||
|
||||
use std::convert::TryFrom;
|
||||
use std::str::FromStr;
|
||||
|
||||
use actix_web::dev::Url;
|
||||
use actix_web::http::Uri;
|
||||
|
||||
/// Escape an HTML string
|
||||
///
|
||||
/// Removes the HTML code included inside a string
|
||||
@ -16,4 +22,19 @@
|
||||
pub fn remove_html_nodes(input: &str) -> String {
|
||||
input.replace("<", "<")
|
||||
.replace(">", ">")
|
||||
}
|
||||
|
||||
/// Check out whether a URL is valid or not
|
||||
///
|
||||
/// ```
|
||||
/// use comunic_server::utils::string_utils::check_url;
|
||||
///
|
||||
/// let url1 = "http://communniquons.org/?url=some&arg2=myname#content3";
|
||||
/// assert_eq!(check_url(url1), true);
|
||||
///
|
||||
/// let url2 = "h@ttp://communniquons.org/?url=some&arg2=myname#content3";
|
||||
/// assert_eq!(check_url(url2), false);
|
||||
/// ```
|
||||
pub fn check_url(url: &str) -> bool {
|
||||
Uri::from_str(url).is_ok()
|
||||
}
|
Loading…
Reference in New Issue
Block a user