Skip to content

Commit 4693521

Browse files
fix: parse json5 capability files when config-json5 is enabled (#11658)
1 parent 74212d4 commit 4693521

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

.changes/json5-capability-files.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri": patch:bug
3+
"tauri-utils": patch:bug
4+
---
5+
6+
Fix `.json5` capability files not recognized even with `config-json5` feature enabled

crates/tauri-utils/src/acl/build.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ pub const PERMISSION_FILE_EXTENSIONS: &[&str] = &["json", "toml"];
3434
pub const PERMISSION_DOCS_FILE_NAME: &str = "reference.md";
3535

3636
/// Allowed capability file extensions
37-
const CAPABILITY_FILE_EXTENSIONS: &[&str] = &["json", "toml"];
37+
const CAPABILITY_FILE_EXTENSIONS: &[&str] = &[
38+
"json",
39+
#[cfg(feature = "config-json5")]
40+
"json5",
41+
"toml",
42+
];
3843

3944
/// Known folder name of the capability schemas
4045
const CAPABILITIES_SCHEMA_FOLDER_NAME: &str = "schemas";

crates/tauri-utils/src/acl/capability.rs

+2
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ impl CapabilityFile {
267267
let file: Self = match ext.as_str() {
268268
"toml" => toml::from_str(&capability_file)?,
269269
"json" => serde_json::from_str(&capability_file)?,
270+
#[cfg(feature = "config-json5")]
271+
"json5" => json5::from_str(&capability_file)?,
270272
_ => return Err(super::Error::UnknownCapabilityFormat(ext)),
271273
};
272274
Ok(file)

crates/tauri-utils/src/acl/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ pub enum Error {
103103
#[error("failed to parse JSON: {0}")]
104104
Json(#[from] serde_json::Error),
105105

106+
/// Invalid JSON5 encountered
107+
#[cfg(feature = "config-json5")]
108+
#[error("failed to parse JSON5: {0}")]
109+
Json5(#[from] json5::Error),
110+
106111
/// Invalid permissions file format
107112
#[error("unknown permission format {0}")]
108113
UnknownPermissionFormat(String),

0 commit comments

Comments
 (0)