Skip to content

Commit c870065

Browse files
fix(tauri-cli): prevent accidental object permission rm (#11985)
1 parent cdd1ebf commit c870065

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

.changes/fix-cli-permission-typing.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-cli": patch:bug
3+
"@tauri-apps/cli": patch:bug
4+
---
5+
6+
Fix `tauri remove` from removing object type (`{}`) permissions.

crates/tauri-cli/src/acl/permission/rm.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,16 @@ fn rm_permission_from_capabilities(identifier: &str, dir: &Path) -> Result<()> {
8686
if let Ok(mut value) = content.parse::<toml_edit::DocumentMut>() {
8787
if let Some(permissions) = value.get_mut("permissions").and_then(|p| p.as_array_mut()) {
8888
let prev_len = permissions.len();
89-
permissions.retain(|p| {
90-
p.as_str()
91-
.map(|p| !identifier_match(identifier, p))
92-
.unwrap_or(false)
89+
permissions.retain(|p| match p {
90+
toml_edit::Value::String(s) => !identifier_match(identifier, s.value()),
91+
toml_edit::Value::InlineTable(o) => {
92+
if let Some(toml_edit::Value::String(permission_name)) = o.get("identifier") {
93+
return !identifier_match(identifier, permission_name.value());
94+
}
95+
96+
true
97+
}
98+
_ => false,
9399
});
94100
if prev_len != permissions.len() {
95101
std::fs::write(&path, value.to_string())?;
@@ -103,10 +109,16 @@ fn rm_permission_from_capabilities(identifier: &str, dir: &Path) -> Result<()> {
103109
if let Ok(mut value) = serde_json::from_slice::<serde_json::Value>(&content) {
104110
if let Some(permissions) = value.get_mut("permissions").and_then(|p| p.as_array_mut()) {
105111
let prev_len = permissions.len();
106-
permissions.retain(|p| {
107-
p.as_str()
108-
.map(|p| !identifier_match(identifier, p))
109-
.unwrap_or(false)
112+
permissions.retain(|p| match p {
113+
serde_json::Value::String(s) => !identifier_match(identifier, s),
114+
serde_json::Value::Object(o) => {
115+
if let Some(serde_json::Value::String(permission_name)) = o.get("identifier") {
116+
return !identifier_match(identifier, permission_name);
117+
}
118+
119+
true
120+
}
121+
_ => false,
110122
});
111123
if prev_len != permissions.len() {
112124
std::fs::write(&path, serde_json::to_vec_pretty(&value)?)?;

0 commit comments

Comments
 (0)