remove regex and urlpattern deps

pull/2019/head
amrbashir 9 months ago
parent f7244d5645
commit 51581012f9
No known key found for this signature in database
GPG Key ID: BBD7A47A2003FF33

5
Cargo.lock generated

@ -6564,18 +6564,17 @@ name = "tauri-plugin-opener"
version = "1.0.0" version = "1.0.0"
dependencies = [ dependencies = [
"dunce", "dunce",
"glob",
"objc2-app-kit", "objc2-app-kit",
"objc2-foundation", "objc2-foundation",
"open", "open",
"regex",
"schemars", "schemars",
"serde", "serde",
"serde_json", "serde_json",
"tauri", "tauri",
"tauri-plugin", "tauri-plugin",
"thiserror", "thiserror 2.0.3",
"url", "url",
"urlpattern",
"windows 0.54.0", "windows 0.54.0",
"zbus", "zbus",
] ]

@ -22,7 +22,6 @@ schemars = "0.8"
dunce = "1" dunce = "1"
specta = "=2.0.0-rc.20" specta = "=2.0.0-rc.20"
glob = "0.3" glob = "0.3"
urlpattern = "0.3"
zbus = "4" zbus = "4"
#tauri-specta = "=2.0.0-rc.11" #tauri-specta = "=2.0.0-rc.11"

@ -25,7 +25,7 @@ tauri-plugin = { workspace = true, features = ["build"] }
schemars = { workspace = true } schemars = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
url = { workspace = true } url = { workspace = true }
urlpattern = { workspace = true } urlpattern = "0.3"
regex = "1" regex = "1"
[dependencies] [dependencies]
@ -35,7 +35,7 @@ tauri = { workspace = true }
thiserror = { workspace = true } thiserror = { workspace = true }
tokio = { version = "1", features = ["sync", "macros"] } tokio = { version = "1", features = ["sync", "macros"] }
tauri-plugin-fs = { path = "../fs", version = "2.0.3" } tauri-plugin-fs = { path = "../fs", version = "2.0.3" }
urlpattern = { workspace = true } urlpattern = "0.3"
regex = "1" regex = "1"
http = "1" http = "1"
reqwest = { version = "0.12", default-features = false } reqwest = { version = "0.12", default-features = false }

@ -1,6 +1,7 @@
[package] [package]
name = "tauri-plugin-opener" name = "tauri-plugin-opener"
version = "1.0.0" version = "1.0.0"
description = "Open files and URLs using their default application."
edition = { workspace = true } edition = { workspace = true }
authors = { workspace = true } authors = { workspace = true }
license = { workspace = true } license = { workspace = true }
@ -26,8 +27,6 @@ ios = { level = "partial", notes = "Only allows to open URLs via `open`" }
tauri-plugin = { workspace = true, features = ["build"] } tauri-plugin = { workspace = true, features = ["build"] }
schemars = { workspace = true } schemars = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
urlpattern = { workspace = true }
regex = "1"
[dependencies] [dependencies]
serde = { workspace = true } serde = { workspace = true }
@ -35,9 +34,8 @@ serde_json = { workspace = true }
tauri = { workspace = true } tauri = { workspace = true }
thiserror = { workspace = true } thiserror = { workspace = true }
open = { version = "5", features = ["shellexecute-on-windows"] } open = { version = "5", features = ["shellexecute-on-windows"] }
urlpattern = { workspace = true }
regex = "1"
url = { workspace = true } url = { workspace = true }
glob = { workspace = true }
[target."cfg(windows)".dependencies] [target."cfg(windows)".dependencies]
dunce = { workspace = true } dunce = { workspace = true }

@ -15,15 +15,12 @@ mod scope;
enum OpenerScopeEntry { enum OpenerScopeEntry {
Url { Url {
/// A URL that can be opened by the webview when using the Opener APIs. /// A URL that can be opened by the webview when using the Opener APIs.
/// Wildcards can be used following the URL pattern standard.
/// ///
/// See [the URL Pattern spec](https://urlpattern.spec.whatwg.org/) for more information. /// Wildcards can be used following the UNIX glob pattern.
/// ///
/// Examples: /// Examples:
/// ///
/// - "https://*" : allows all HTTPS origin on port 443 /// - "https://*" : allows all HTTPS origin
///
/// - "https://*:*" : allows all HTTPS origin on any port
/// ///
/// - "https://*.github.com/tauri-apps/tauri": allows any subdomain of "github.com" with the "tauri-apps/api" path /// - "https://*.github.com/tauri-apps/tauri": allows any subdomain of "github.com" with the "tauri-apps/api" path
/// ///

@ -1,6 +1,7 @@
{ {
"name": "@tauri-apps/plugin-opener", "name": "@tauri-apps/plugin-opener",
"version": "1.0.0", "version": "1.0.0",
"description": "Open files and URLs using their default application.",
"license": "MIT OR Apache-2.0", "license": "MIT OR Apache-2.0",
"authors": [ "authors": [
"Tauri Programme within The Commons Conservancy" "Tauri Programme within The Commons Conservancy"

@ -11,7 +11,7 @@ url = "mailto:*"
url = "tel:*" url = "tel:*"
[[permission.scope.allow]] [[permission.scope.allow]]
url = "http://*:*" url = "http://*"
[[permission.scope.allow]] [[permission.scope.allow]]
url = "https://*:*" url = "https://*"

@ -73,9 +73,9 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
.js_init_script(include_str!("init-iife.js").to_string()) .js_init_script(include_str!("init-iife.js").to_string())
.setup(|app, _api| { .setup(|app, _api| {
#[cfg(target_os = "android")] #[cfg(target_os = "android")]
let handle = api.register_android_plugin(PLUGIN_IDENTIFIER, "OpenerPlugin")?; let handle = _api.register_android_plugin(PLUGIN_IDENTIFIER, "OpenerPlugin")?;
#[cfg(target_os = "ios")] #[cfg(target_os = "ios")]
let handle = api.register_ios_plugin(init_plugin_opener)?; let handle = _api.register_ios_plugin(init_plugin_opener)?;
app.manage(Opener { app.manage(Opener {
app: app.clone(), app: app.clone(),

@ -183,5 +183,7 @@ mod imp {
let workspace = NSWorkspace::new(); let workspace = NSWorkspace::new();
workspace.activateFileViewerSelectingURLs(&urls); workspace.activateFileViewerSelectingURLs(&urls);
} }
Ok(())
} }
} }

@ -7,37 +7,15 @@ use std::{marker::PhantomData, path::PathBuf, sync::Arc};
use tauri::{ipc::ScopeObject, utils::acl::Value, AppHandle, Manager, Runtime}; use tauri::{ipc::ScopeObject, utils::acl::Value, AppHandle, Manager, Runtime};
use url::Url; use url::Url;
use urlpattern::UrlPatternMatchInput;
use crate::{scope_entry::EntryRaw, Error}; use crate::{scope_entry::EntryRaw, Error};
#[derive(Debug)] #[derive(Debug)]
pub enum Entry { pub enum Entry {
Url(Box<urlpattern::UrlPattern>), Url(glob::Pattern),
Path(Option<PathBuf>), Path(Option<PathBuf>),
} }
fn parse_url_pattern(
s: &str,
) -> std::result::Result<urlpattern::UrlPattern, urlpattern::quirks::Error> {
let mut init = urlpattern::UrlPatternInit::parse_constructor_string::<regex::Regex>(s, None)?;
if init.search.as_ref().map(|p| p.is_empty()).unwrap_or(true) {
init.search.replace("*".to_string());
}
if init.hash.as_ref().map(|p| p.is_empty()).unwrap_or(true) {
init.hash.replace("*".to_string());
}
if init
.pathname
.as_ref()
.map(|p| p.is_empty() || p == "/")
.unwrap_or(true)
{
init.pathname.replace("*".to_string());
}
urlpattern::UrlPattern::parse(init, Default::default())
}
impl ScopeObject for Entry { impl ScopeObject for Entry {
type Error = Error; type Error = Error;
@ -48,14 +26,10 @@ impl ScopeObject for Entry {
serde_json::from_value(raw.into()) serde_json::from_value(raw.into())
.and_then(|raw| { .and_then(|raw| {
let entry = match raw { let entry = match raw {
EntryRaw::Url { url } => { EntryRaw::Url { url } => Entry::Url(
let url_pattern = parse_url_pattern(&url).map_err(|e| { glob::Pattern::new(&url)
serde::de::Error::custom(format!( .map_err(|e| serde::de::Error::custom(e.to_string()))?,
"`{url}` is not a valid URL pattern: {e}" ),
))
})?;
Entry::Url(Box::new(url_pattern))
}
EntryRaw::Path { path } => { EntryRaw::Path { path } => {
let path = match app.path().parse(path) { let path = match app.path().parse(path) {
Ok(path) => Some(path), Ok(path) => Some(path),
@ -106,18 +80,14 @@ impl<'a, R: Runtime, M: Manager<R>> Scope<'a, R, M> {
pub fn is_url_allowed(&self, url: Url) -> bool { pub fn is_url_allowed(&self, url: Url) -> bool {
let denied = self.denied.iter().any(|entry| match entry.as_ref() { let denied = self.denied.iter().any(|entry| match entry.as_ref() {
Entry::Url(url_pattern) => url_pattern Entry::Url(url_pattern) => url_pattern.matches(url.as_str()),
.test(UrlPatternMatchInput::Url(url.clone()))
.unwrap_or_default(),
Entry::Path { .. } => false, Entry::Path { .. } => false,
}); });
if denied { if denied {
false false
} else { } else {
self.allowed.iter().any(|entry| match entry.as_ref() { self.allowed.iter().any(|entry| match entry.as_ref() {
Entry::Url(url_pattern) => url_pattern Entry::Url(url_pattern) => url_pattern.matches(url.as_str()),
.test(UrlPatternMatchInput::Url(url.clone()))
.unwrap_or_default(),
Entry::Path { .. } => false, Entry::Path { .. } => false,
}) })
} }

Loading…
Cancel
Save