Browse Source

fix(tauri) ensure css content is loaded inside a string (#884)

Signed-off-by: Chip Reed <chip@chip.sh>
chip 5 năm trước cách đây
mục cha
commit
e3e2e39208
2 tập tin đã thay đổi với 11 bổ sung6 xóa
  1. 5 0
      .changes/load-asset-css.md
  2. 6 6
      tauri/src/endpoints/asset.rs

+ 5 - 0
.changes/load-asset-css.md

@@ -0,0 +1,5 @@
+---
+"tauri": patch
+---
+
+make sure css content injected is inside a string and not injected raw

+ 6 - 6
tauri/src/endpoints/asset.rs

@@ -65,15 +65,15 @@ pub fn load(
           if asset_type == "stylesheet" {
             webview_ref.eval(&format!(
               r#"
-                (function () {{
+                (function (content) {{
                   var css = document.createElement('style')
                   css.type = 'text/css'
-                  if (css.styleSheet)  
-                      css.styleSheet.cssText = {css}
-                  else  
-                      css.appendChild(document.createTextNode({css}))
+                  if (css.styleSheet)
+                      css.styleSheet.cssText = content
+                  else
+                      css.appendChild(document.createTextNode(content))
                   document.getElementsByTagName("head")[0].appendChild(css);
-                }})()
+                }})("{css}")
               "#,
               css = asset_str
             ));