fix: parse json5 capability files when config-json5 is enabled (#11658)

This commit is contained in:
Tony
2024-11-12 22:44:37 +08:00
committed by GitHub
parent 74212d40d8
commit 46935212b6
4 changed files with 19 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"tauri": patch:bug
"tauri-utils": patch:bug
---
Fix `.json5` capability files not recognized even with `config-json5` feature enabled

View File

@@ -34,7 +34,12 @@ pub const PERMISSION_FILE_EXTENSIONS: &[&str] = &["json", "toml"];
pub const PERMISSION_DOCS_FILE_NAME: &str = "reference.md";
/// Allowed capability file extensions
const CAPABILITY_FILE_EXTENSIONS: &[&str] = &["json", "toml"];
const CAPABILITY_FILE_EXTENSIONS: &[&str] = &[
"json",
#[cfg(feature = "config-json5")]
"json5",
"toml",
];
/// Known folder name of the capability schemas
const CAPABILITIES_SCHEMA_FOLDER_NAME: &str = "schemas";

View File

@@ -267,6 +267,8 @@ impl CapabilityFile {
let file: Self = match ext.as_str() {
"toml" => toml::from_str(&capability_file)?,
"json" => serde_json::from_str(&capability_file)?,
#[cfg(feature = "config-json5")]
"json5" => json5::from_str(&capability_file)?,
_ => return Err(super::Error::UnknownCapabilityFormat(ext)),
};
Ok(file)

View File

@@ -103,6 +103,11 @@ pub enum Error {
#[error("failed to parse JSON: {0}")]
Json(#[from] serde_json::Error),
/// Invalid JSON5 encountered
#[cfg(feature = "config-json5")]
#[error("failed to parse JSON5: {0}")]
Json5(#[from] json5::Error),
/// Invalid permissions file format
#[error("unknown permission format {0}")]
UnknownPermissionFormat(String),