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"
dependencies = [
"dunce",
"glob",
"objc2-app-kit",
"objc2-foundation",
"open",
"regex",
"schemars",
"serde",
"serde_json",
"tauri",
"tauri-plugin",
"thiserror",
"thiserror 2.0.3",
"url",
"urlpattern",
"windows 0.54.0",
"zbus",
]

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

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

@ -1,6 +1,7 @@
[package]
name = "tauri-plugin-opener"
version = "1.0.0"
description = "Open files and URLs using their default application."
edition = { workspace = true }
authors = { 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"] }
schemars = { workspace = true }
serde = { workspace = true }
urlpattern = { workspace = true }
regex = "1"
[dependencies]
serde = { workspace = true }
@ -35,9 +34,8 @@ serde_json = { workspace = true }
tauri = { workspace = true }
thiserror = { workspace = true }
open = { version = "5", features = ["shellexecute-on-windows"] }
urlpattern = { workspace = true }
regex = "1"
url = { workspace = true }
glob = { workspace = true }
[target."cfg(windows)".dependencies]
dunce = { workspace = true }

@ -15,15 +15,12 @@ mod scope;
enum OpenerScopeEntry {
Url {
/// 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:
///
/// - "https://*" : allows all HTTPS origin on port 443
///
/// - "https://*:*" : allows all HTTPS origin on any port
/// - "https://*" : allows all HTTPS origin
///
/// - "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",
"version": "1.0.0",
"description": "Open files and URLs using their default application.",
"license": "MIT OR Apache-2.0",
"authors": [
"Tauri Programme within The Commons Conservancy"

@ -11,7 +11,7 @@ url = "mailto:*"
url = "tel:*"
[[permission.scope.allow]]
url = "http://*:*"
url = "http://*"
[[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())
.setup(|app, _api| {
#[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")]
let handle = api.register_ios_plugin(init_plugin_opener)?;
let handle = _api.register_ios_plugin(init_plugin_opener)?;
app.manage(Opener {
app: app.clone(),

@ -183,5 +183,7 @@ mod imp {
let workspace = NSWorkspace::new();
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 url::Url;
use urlpattern::UrlPatternMatchInput;
use crate::{scope_entry::EntryRaw, Error};
#[derive(Debug)]
pub enum Entry {
Url(Box<urlpattern::UrlPattern>),
Url(glob::Pattern),
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 {
type Error = Error;
@ -48,14 +26,10 @@ impl ScopeObject for Entry {
serde_json::from_value(raw.into())
.and_then(|raw| {
let entry = match raw {
EntryRaw::Url { url } => {
let url_pattern = parse_url_pattern(&url).map_err(|e| {
serde::de::Error::custom(format!(
"`{url}` is not a valid URL pattern: {e}"
))
})?;
Entry::Url(Box::new(url_pattern))
}
EntryRaw::Url { url } => Entry::Url(
glob::Pattern::new(&url)
.map_err(|e| serde::de::Error::custom(e.to_string()))?,
),
EntryRaw::Path { path } => {
let path = match app.path().parse(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 {
let denied = self.denied.iter().any(|entry| match entry.as_ref() {
Entry::Url(url_pattern) => url_pattern
.test(UrlPatternMatchInput::Url(url.clone()))
.unwrap_or_default(),
Entry::Url(url_pattern) => url_pattern.matches(url.as_str()),
Entry::Path { .. } => false,
});
if denied {
false
} else {
self.allowed.iter().any(|entry| match entry.as_ref() {
Entry::Url(url_pattern) => url_pattern
.test(UrlPatternMatchInput::Url(url.clone()))
.unwrap_or_default(),
Entry::Url(url_pattern) => url_pattern.matches(url.as_str()),
Entry::Path { .. } => false,
})
}

Loading…
Cancel
Save