summaryrefslogtreecommitdiffstats
path: root/src/config/input.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config/input.rs')
-rw-r--r--src/config/input.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/config/input.rs b/src/config/input.rs
index b1cf6c3..fc29c49 100644
--- a/src/config/input.rs
+++ b/src/config/input.rs
@@ -3,6 +3,8 @@ use crate::utils::sha256sum;
use anyhow::{bail, Context, Result};
use base64::{self, engine::general_purpose::STANDARD, Engine};
+use fancy_regex::Regex;
+use lazy_static::lazy_static;
use mime_guess::from_path;
use std::{
collections::HashMap,
@@ -13,6 +15,10 @@ use std::{
const IMAGE_EXTS: [&str; 5] = ["png", "jpeg", "jpg", "webp", "gif"];
+lazy_static! {
+ static ref URL_RE: Regex = Regex::new(r"^[A-Za-z0-9_-]{2,}:/").unwrap();
+}
+
#[derive(Debug, Clone)]
pub struct Input {
text: String,
@@ -128,10 +134,7 @@ pub fn resolve_data_url(data_urls: &HashMap<String, String>, data_url: String) -
}
fn resolve_path(file: &str) -> Option<PathBuf> {
- if ["https://", "http://", "data:"]
- .iter()
- .any(|v| file.starts_with(v))
- {
+ if let Ok(true) = URL_RE.is_match(file) {
return None;
}
let path = if let (Some(file), Some(home)) = (file.strip_prefix('~'), dirs::home_dir()) {