mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-12-25 03:33:36 +03:00
feat: validate window label [TRI-021] (#13)
This commit is contained in:
parent
d42ccfb34f
commit
680554de3e
6
.changes/validate-window-label.md
Normal file
6
.changes/validate-window-label.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"tauri": patch
|
||||
"tauri-runtime": patch
|
||||
---
|
||||
|
||||
The window label is now validated and must be alphanumeric, resulting in a panic if it isn't.
|
@ -109,6 +109,13 @@ pub struct PendingWindow<R: Runtime> {
|
||||
pub js_event_listeners: Arc<Mutex<HashMap<String, HashSet<u64>>>>,
|
||||
}
|
||||
|
||||
fn validate_label(label: &str) {
|
||||
assert!(
|
||||
label.chars().all(char::is_alphanumeric),
|
||||
"Window label must be alphanumeric"
|
||||
);
|
||||
}
|
||||
|
||||
impl<R: Runtime> PendingWindow<R> {
|
||||
/// Create a new [`PendingWindow`] with a label and starting url.
|
||||
pub fn new(
|
||||
@ -120,11 +127,13 @@ impl<R: Runtime> PendingWindow<R> {
|
||||
if let Some(menu) = window_builder.get_menu() {
|
||||
get_menu_ids(&mut menu_ids, menu);
|
||||
}
|
||||
let label = label.into();
|
||||
validate_label(&label);
|
||||
Self {
|
||||
window_builder,
|
||||
webview_attributes,
|
||||
uri_scheme_protocols: Default::default(),
|
||||
label: label.into(),
|
||||
label,
|
||||
ipc_handler: None,
|
||||
file_drop_handler: None,
|
||||
url: "tauri://localhost".to_string(),
|
||||
@ -144,11 +153,13 @@ impl<R: Runtime> PendingWindow<R> {
|
||||
if let Some(menu) = window_builder.get_menu() {
|
||||
get_menu_ids(&mut menu_ids, menu);
|
||||
}
|
||||
let label = label.into();
|
||||
validate_label(&label);
|
||||
Self {
|
||||
window_builder,
|
||||
webview_attributes,
|
||||
uri_scheme_protocols: Default::default(),
|
||||
label: label.into(),
|
||||
label,
|
||||
ipc_handler: None,
|
||||
file_drop_handler: None,
|
||||
url: "tauri://localhost".to_string(),
|
||||
|
@ -403,7 +403,7 @@ impl CliConfig {
|
||||
#[cfg_attr(feature = "schema", derive(JsonSchema))]
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
pub struct WindowConfig {
|
||||
/// The window identifier.
|
||||
/// The window identifier. It must be alphanumeric.
|
||||
#[serde(default = "default_window_label")]
|
||||
pub label: String,
|
||||
/// The window webview URL.
|
||||
|
@ -1094,6 +1094,11 @@ class WindowManager extends WebviewWindowHandle {
|
||||
* ```
|
||||
*/
|
||||
class WebviewWindow extends WindowManager {
|
||||
/**
|
||||
* Creates a new WebviewWindow.
|
||||
* * @param label The webview window label. It must be alphanumeric.
|
||||
* @returns The WebviewWindow instance to communicate with the webview.
|
||||
*/
|
||||
constructor(
|
||||
label: WindowLabel | null | undefined,
|
||||
options: WindowOptions = {}
|
||||
|
@ -1405,7 +1405,7 @@
|
||||
"format": "double"
|
||||
},
|
||||
"label": {
|
||||
"description": "The window identifier.",
|
||||
"description": "The window identifier. It must be alphanumeric.",
|
||||
"default": "main",
|
||||
"type": "string"
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user