From 3b4ed970e663f5bffbfe0358610f9c3f157c513f Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Mon, 11 Jul 2022 20:41:34 -0300 Subject: [PATCH] feat(codegen): validate `__TAURI_ISOLATION_HOOK__` is referenced (#4631) --- .changes/validate-isolation-hook-set.md | 5 +++++ core/tauri-codegen/src/context.rs | 19 +++++++++++++++++-- core/tauri-codegen/src/embedded_assets.rs | 17 ++++++++++++++--- 3 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 .changes/validate-isolation-hook-set.md diff --git a/.changes/validate-isolation-hook-set.md b/.changes/validate-isolation-hook-set.md new file mode 100644 index 000000000..824783240 --- /dev/null +++ b/.changes/validate-isolation-hook-set.md @@ -0,0 +1,5 @@ +--- +"tauri-codegen": patch +--- + +Validate `__TAURI_ISOLATION_HOOK__` being set by a file in the isolation application. diff --git a/core/tauri-codegen/src/context.rs b/core/tauri-codegen/src/context.rs index 202b19cca..75aa8926b 100644 --- a/core/tauri-codegen/src/context.rs +++ b/core/tauri-codegen/src/context.rs @@ -330,13 +330,28 @@ pub fn context_codegen(data: ContextData) -> Result, options: &AssetOptions, - map: impl Fn(&AssetKey, &Path, &mut Vec, &mut CspHashes) -> Result<(), EmbeddedAssetsError>, + mut map: impl FnMut( + &AssetKey, + &Path, + &mut Vec, + &mut CspHashes, + ) -> Result<(), EmbeddedAssetsError>, ) -> Result { // we need to pre-compute all files now, so that we can inject data from all files into a few let RawEmbeddedAssets { paths, csp_hashes } = RawEmbeddedAssets::new(input.into(), options)?; @@ -262,7 +267,8 @@ impl EmbeddedAssets { assets: HashMap::new(), }, move |mut state, (prefix, entry)| { - let (key, asset) = Self::compress_file(&prefix, entry.path(), &map, &mut state.csp_hashes)?; + let (key, asset) = + Self::compress_file(&prefix, entry.path(), &mut map, &mut state.csp_hashes)?; state.assets.insert(key, asset); Result::<_, EmbeddedAssetsError>::Ok(state) }, @@ -292,7 +298,12 @@ impl EmbeddedAssets { fn compress_file( prefix: &Path, path: &Path, - map: &impl Fn(&AssetKey, &Path, &mut Vec, &mut CspHashes) -> Result<(), EmbeddedAssetsError>, + map: &mut impl FnMut( + &AssetKey, + &Path, + &mut Vec, + &mut CspHashes, + ) -> Result<(), EmbeddedAssetsError>, csp_hashes: &mut CspHashes, ) -> Result { let mut input = std::fs::read(path).map_err(|error| EmbeddedAssetsError::AssetRead {