Skip to content

Commit d0d873e

Browse files
authored
feat(core): add support to mailto: and tel: links, closes #5521 (#5544)
1 parent 9db9e6c commit d0d873e

File tree

10 files changed

+18
-13
lines changed

10 files changed

+18
-13
lines changed

.changes/open-links-mail-tel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": minor
3+
---
4+
5+
Added support to `mailto:` and `tel:` links on the shell API.

core/config-schema/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,7 @@
22112211
"description": "Defines the `shell > open` api scope.",
22122212
"anyOf": [
22132213
{
2214-
"description": "If the shell open API should be enabled.\n\nIf enabled, the default validation regex (`^https?://`) is used.",
2214+
"description": "If the shell open API should be enabled.\n\nIf enabled, the default validation regex (`^((mailto:\\w+)|(tel:\\w+)|(https?://\\w+)).+`) is used.",
22152215
"type": "boolean"
22162216
},
22172217
{

core/tauri-codegen/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
414414
let shell_scope_open = match &config.tauri.allowlist.shell.open {
415415
ShellAllowlistOpen::Flag(false) => quote!(::std::option::Option::None),
416416
ShellAllowlistOpen::Flag(true) => {
417-
quote!(::std::option::Option::Some(#root::regex::Regex::new("^https?://").unwrap()))
417+
quote!(::std::option::Option::Some(#root::regex::Regex::new(r#"^((mailto:\w+)|(tel:\w+)|(https?://\w+)).+"#).unwrap()))
418418
}
419419
ShellAllowlistOpen::Validate(regex) => match Regex::new(regex) {
420420
Ok(_) => quote!(::std::option::Option::Some(#root::regex::Regex::new(#regex).unwrap())),

core/tauri-utils/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1599,7 +1599,7 @@ pub struct ShellAllowlistScope(pub Vec<ShellAllowedCommand>);
15991599
pub enum ShellAllowlistOpen {
16001600
/// If the shell open API should be enabled.
16011601
///
1602-
/// If enabled, the default validation regex (`^https?://`) is used.
1602+
/// If enabled, the default validation regex (`^((mailto:\w+)|(tel:\w+)|(https?://\w+)).+`) is used.
16031603
Flag(bool),
16041604

16051605
/// Enable the shell open API, with a custom regex that the opened path must match against.

core/tauri/scripts/bundle.global.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/tauri/scripts/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
if (target.matches('a')) {
9797
if (
9898
target.href &&
99-
target.href.startsWith('http') &&
99+
(['http://', 'https://', 'mailto:', 'tel:'].some(v => target.href.startsWith(v))) &&
100100
target.target === '_blank'
101101
) {
102102
window.__TAURI_INVOKE__('tauri', {

core/tauri/src/api/shell.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl Program {
9191

9292
/// Opens path or URL with the program specified in `with`, or system default if `None`.
9393
///
94-
/// The path will be matched against the shell open validation regex, defaulting to `^https?://`.
94+
/// The path will be matched against the shell open validation regex, defaulting to `^((mailto:\w+)|(tel:\w+)|(https?://\w+)).+`.
9595
/// A custom validation regex may be supplied in the config in `tauri > allowlist > scope > open`.
9696
///
9797
/// # Examples

core/tauri/src/scope/shell.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ impl Scope {
301301
/// Open a path in the default (or specified) browser.
302302
///
303303
/// The path is validated against the `tauri > allowlist > shell > open` validation regex, which
304-
/// defaults to `^https?://`.
304+
/// defaults to `^((mailto:\w+)|(tel:\w+)|(https?://\w+)).+`.
305305
#[cfg(feature = "shell-open-api")]
306306
pub fn open(&self, path: &str, with: Option<Program>) -> Result<(), ScopeError> {
307307
// ensure we pass validation if the configuration has one

tooling/api/src/shell.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* ### Restricting access to the {@link open | `open`} API
3333
*
3434
* On the allowlist, `open: true` means that the {@link open} API can be used with any URL,
35-
* as the argument is validated with the `^https?://` regex.
35+
* as the argument is validated with the `^((mailto:\w+)|(tel:\w+)|(https?://\w+)).+` regex.
3636
* You can change that regex by changing the boolean value to a string, e.g. `open: ^https://github.com/`.
3737
*
3838
* ### Restricting access to the {@link Command | `Command`} APIs
@@ -553,7 +553,7 @@ type CommandEvent =
553553
*
554554
* @param path The path or URL to open.
555555
* This value is matched against the string regex defined on `tauri.conf.json > tauri > allowlist > shell > open`,
556-
* which defaults to `^https?://`.
556+
* which defaults to `^((mailto:\w+)|(tel:\w+)|(https?://\w+)).+`.
557557
* @param openWith The app to open the file or URL with.
558558
* Defaults to the system default application for the specified path type.
559559
*

tooling/cli/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,7 @@
22112211
"description": "Defines the `shell > open` api scope.",
22122212
"anyOf": [
22132213
{
2214-
"description": "If the shell open API should be enabled.\n\nIf enabled, the default validation regex (`^https?://`) is used.",
2214+
"description": "If the shell open API should be enabled.\n\nIf enabled, the default validation regex (`^((mailto:\\w+)|(tel:\\w+)|(https?://\\w+)).+`) is used.",
22152215
"type": "boolean"
22162216
},
22172217
{

0 commit comments

Comments
 (0)