pastes: validate URLs using regex
Signed-off-by: ATechnoHazard <amolele@gmail.com>
This commit is contained in:
parent
8ac5b3ca8b
commit
c075068649
17
Cargo.lock
generated
17
Cargo.lock
generated
@ -806,6 +806,7 @@ dependencies = [
|
||||
"jirachi",
|
||||
"jirachi_cli",
|
||||
"jsonwebtoken",
|
||||
"regex 1.3.9",
|
||||
"rocket",
|
||||
"rocket_contrib",
|
||||
"rocket_cors",
|
||||
@ -816,7 +817,6 @@ dependencies = [
|
||||
"slog-async",
|
||||
"slog-term",
|
||||
"uuid",
|
||||
"validator",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1873,21 +1873,6 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "validator"
|
||||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e60fadf92c22236de4028ceb0b8af50ed3430d41ad43d7a7d63b6bd1a8f47c38"
|
||||
dependencies = [
|
||||
"idna 0.2.0",
|
||||
"lazy_static",
|
||||
"regex 1.3.9",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
"url 2.1.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.10"
|
||||
|
@ -23,13 +23,13 @@ jsonwebtoken = "7.2.0"
|
||||
slog = "2.5.2"
|
||||
slog-term = "2.6.0"
|
||||
anyhow = "1.0.31"
|
||||
validator = "0.10.1"
|
||||
slog-async = "2.5.0"
|
||||
bcrypt = "0.8.1"
|
||||
chrono = "0.4.13"
|
||||
uuid = { version = "0.8.1", features = ["serde", "v4"] }
|
||||
jirachi = { version = "0.1.4", features = ["collision-resistant"] }
|
||||
rocket_cors = "0.5.1"
|
||||
regex = "1.3.9"
|
||||
|
||||
[dev-dependencies]
|
||||
diesel_cli = { version = "1.4.1", default-features = false, features = ["postgres"] }
|
||||
|
@ -1,11 +1,13 @@
|
||||
use anyhow::Result;
|
||||
use diesel::pg::PgConnection;
|
||||
use regex::Regex;
|
||||
|
||||
use super::entity::Paste;
|
||||
use super::postgres;
|
||||
|
||||
pub fn create_paste(paste: &mut Paste, conn: &PgConnection) -> Result<usize> {
|
||||
paste.is_url = Some(validator::validate_url(paste.content.clone()));
|
||||
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();
|
||||
paste.is_url = Some(re.is_match(&*paste.content.clone()));
|
||||
postgres::create_paste(paste, conn)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user