Skip to content

Commit 680554d

Browse files
committed
feat: validate window label [TRI-021] (#13)
1 parent d42ccfb commit 680554d

5 files changed

Lines changed: 26 additions & 4 deletions

File tree

.changes/validate-window-label.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri": patch
3+
"tauri-runtime": patch
4+
---
5+
6+
The window label is now validated and must be alphanumeric, resulting in a panic if it isn't.

core/tauri-runtime/src/window.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ pub struct PendingWindow<R: Runtime> {
109109
pub js_event_listeners: Arc<Mutex<HashMap<String, HashSet<u64>>>>,
110110
}
111111

112+
fn validate_label(label: &str) {
113+
assert!(
114+
label.chars().all(char::is_alphanumeric),
115+
"Window label must be alphanumeric"
116+
);
117+
}
118+
112119
impl<R: Runtime> PendingWindow<R> {
113120
/// Create a new [`PendingWindow`] with a label and starting url.
114121
pub fn new(
@@ -120,11 +127,13 @@ impl<R: Runtime> PendingWindow<R> {
120127
if let Some(menu) = window_builder.get_menu() {
121128
get_menu_ids(&mut menu_ids, menu);
122129
}
130+
let label = label.into();
131+
validate_label(&label);
123132
Self {
124133
window_builder,
125134
webview_attributes,
126135
uri_scheme_protocols: Default::default(),
127-
label: label.into(),
136+
label,
128137
ipc_handler: None,
129138
file_drop_handler: None,
130139
url: "tauri://localhost".to_string(),
@@ -144,11 +153,13 @@ impl<R: Runtime> PendingWindow<R> {
144153
if let Some(menu) = window_builder.get_menu() {
145154
get_menu_ids(&mut menu_ids, menu);
146155
}
156+
let label = label.into();
157+
validate_label(&label);
147158
Self {
148159
window_builder,
149160
webview_attributes,
150161
uri_scheme_protocols: Default::default(),
151-
label: label.into(),
162+
label,
152163
ipc_handler: None,
153164
file_drop_handler: None,
154165
url: "tauri://localhost".to_string(),

core/tauri-utils/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ impl CliConfig {
403403
#[cfg_attr(feature = "schema", derive(JsonSchema))]
404404
#[serde(rename_all = "camelCase", deny_unknown_fields)]
405405
pub struct WindowConfig {
406-
/// The window identifier.
406+
/// The window identifier. It must be alphanumeric.
407407
#[serde(default = "default_window_label")]
408408
pub label: String,
409409
/// The window webview URL.

tooling/api/src/window.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,11 @@ class WindowManager extends WebviewWindowHandle {
10941094
* ```
10951095
*/
10961096
class WebviewWindow extends WindowManager {
1097+
/**
1098+
* Creates a new WebviewWindow.
1099+
* * @param label The webview window label. It must be alphanumeric.
1100+
* @returns The WebviewWindow instance to communicate with the webview.
1101+
*/
10971102
constructor(
10981103
label: WindowLabel | null | undefined,
10991104
options: WindowOptions = {}

tooling/cli.rs/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,7 @@
14051405
"format": "double"
14061406
},
14071407
"label": {
1408-
"description": "The window identifier.",
1408+
"description": "The window identifier. It must be alphanumeric.",
14091409
"default": "main",
14101410
"type": "string"
14111411
},

0 commit comments

Comments
 (0)