From 80040152a2885ef182d52da9e9c76f95f93db0b3 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Tue, 4 Oct 2022 00:28:30 +0100 Subject: [PATCH] Add parse::url::scheme function for parsing a url protocol/scheme Closes #1304 --- lib/src/fnc/mod.rs | 1 + lib/src/fnc/parse.rs | 8 ++++++++ lib/src/sql/function.rs | 1 + 3 files changed, 10 insertions(+) diff --git a/lib/src/fnc/mod.rs b/lib/src/fnc/mod.rs index ad9bf006..959ee280 100644 --- a/lib/src/fnc/mod.rs +++ b/lib/src/fnc/mod.rs @@ -140,6 +140,7 @@ pub fn synchronous(ctx: &Context<'_>, name: &str, args: Vec) -> Result parse::url::path, "parse::url::port" => parse::url::port, "parse::url::query" => parse::url::query, + "parse::url::scheme" => parse::url::scheme, // "rand::bool" => rand::bool, "rand::enum" => rand::r#enum, diff --git a/lib/src/fnc/parse.rs b/lib/src/fnc/parse.rs index f7411568..d416c4d2 100644 --- a/lib/src/fnc/parse.rs +++ b/lib/src/fnc/parse.rs @@ -110,4 +110,12 @@ pub mod url { Err(_) => Ok(Value::None), } } + + pub fn scheme((string,): (String,)) -> Result { + // Parse the URL + match Url::parse(&string) { + Ok(v) => Ok(v.scheme().into()), + Err(_) => Ok(Value::None), + } + } } diff --git a/lib/src/sql/function.rs b/lib/src/sql/function.rs index 7cd1bdb4..91b8a094 100644 --- a/lib/src/sql/function.rs +++ b/lib/src/sql/function.rs @@ -387,6 +387,7 @@ fn function_parse(i: &str) -> IResult<&str, &str> { tag("parse::url::port"), tag("parse::url::path"), tag("parse::url::query"), + tag("parse::url::scheme"), ))(i) }