paste: make URL regex case insensitive

Signed-off-by: ATechnoHazard <amolele@gmail.com>
This commit is contained in:
Amogh Lele 2020-09-24 23:17:29 +05:30
parent 2a3634e5de
commit ebe7bf4594
No known key found for this signature in database
GPG Key ID: F475143EDEDEBA3C

View File

@ -1,12 +1,12 @@
use anyhow::Result;
use diesel::pg::PgConnection;
use regex::Regex;
use regex::RegexBuilder;
use super::entity::Paste;
use super::postgres;
pub fn create_paste(paste: &mut Paste, conn: &PgConnection) -> Result<usize> {
let re = Regex::new("^(https?://)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(:\\d+)?(/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=-]*)?(#[-a-z\\d_]*)?$").unwrap();
let re = RegexBuilder::new("^(https?://)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(:\\d+)?(/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=-]*)?(#[-a-z\\d_]*)?$").case_insensitive(true).build().unwrap();
paste.is_url = Some(re.is_match(&*paste.content.clone()));
postgres::create_paste(paste, conn)
}