fix: skip empty script tag for CSP hash properly (#14274)

* fix: skip empty script tag for CSP hash properly

* add change file

---------

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
This commit is contained in:
Tony
2025-10-10 19:11:08 +08:00
committed by GitHub
parent b5aa018702
commit c5008b829d
2 changed files with 6 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
"tauri-codegen": patch:bug
---
Do not hash empty scripts when generating the Content-Security-Policy SHA-256 hashes.

View File

@@ -45,7 +45,7 @@ pub struct ContextData {
}
fn inject_script_hashes(document: &NodeRef, key: &AssetKey, csp_hashes: &mut CspHashes) {
if let Ok(inline_script_elements) = document.select("script:not(empty)") {
if let Ok(inline_script_elements) = document.select("script:not(:empty)") {
let mut scripts = Vec::new();
for inline_script_el in inline_script_elements {
let script = inline_script_el.as_node().text_contents();