mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
fix: parse json5 capability files when config-json5 is enabled (#11658)
This commit is contained in:
6
.changes/json5-capability-files.md
Normal file
6
.changes/json5-capability-files.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"tauri": patch:bug
|
||||
"tauri-utils": patch:bug
|
||||
---
|
||||
|
||||
Fix `.json5` capability files not recognized even with `config-json5` feature enabled
|
||||
@@ -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";
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user