Bläddra i källkod

fix(core): Clippy fixes. (#7869)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
martin frances 1 år sedan
förälder
incheckning
8db26bd3e9
2 ändrade filer med 15 tillägg och 16 borttagningar
  1. 6 7
      core/tauri-codegen/src/context.rs
  2. 9 9
      core/tauri-utils/src/html.rs

+ 6 - 7
core/tauri-codegen/src/context.rs

@@ -40,13 +40,13 @@ fn map_core_assets(
     if path.extension() == Some(OsStr::new("html")) {
       #[allow(clippy::collapsible_if)]
       if csp {
-        let mut document = parse_html(String::from_utf8_lossy(input).into_owned());
+        let document = parse_html(String::from_utf8_lossy(input).into_owned());
 
         if target == Target::Linux {
-          ::tauri_utils::html::inject_csp_token(&mut document);
+          ::tauri_utils::html::inject_csp_token(&document);
         }
 
-        inject_nonce_token(&mut document, &dangerous_disable_asset_csp_modification);
+        inject_nonce_token(&document, &dangerous_disable_asset_csp_modification);
 
         if dangerous_disable_asset_csp_modification.can_modify("script-src") {
           if let Ok(inline_script_elements) = document.select("script:not(empty)") {
@@ -97,14 +97,13 @@ fn map_isolation(
 ) -> impl Fn(&AssetKey, &Path, &mut Vec<u8>, &mut CspHashes) -> Result<(), EmbeddedAssetsError> {
   move |_key, path, input, _csp_hashes| {
     if path.extension() == Some(OsStr::new("html")) {
-      let mut isolation_html =
-        tauri_utils::html::parse(String::from_utf8_lossy(input).into_owned());
+      let isolation_html = tauri_utils::html::parse(String::from_utf8_lossy(input).into_owned());
 
       // this is appended, so no need to reverse order it
-      tauri_utils::html::inject_codegen_isolation_script(&mut isolation_html);
+      tauri_utils::html::inject_codegen_isolation_script(&isolation_html);
 
       // temporary workaround for windows not loading assets
-      tauri_utils::html::inline_isolation(&mut isolation_html, &dir);
+      tauri_utils::html::inline_isolation(&isolation_html, &dir);
 
       *input = isolation_html.to_string().as_bytes().to_vec()
     }

+ 9 - 9
core/tauri-utils/src/html.rs

@@ -119,7 +119,7 @@ pub fn parse(html: String) -> NodeRef {
   kuchiki::parse_html().one(html)
 }
 
-fn with_head<F: FnOnce(&NodeRef)>(document: &mut NodeRef, f: F) {
+fn with_head<F: FnOnce(&NodeRef)>(document: &NodeRef, f: F) {
   if let Ok(ref node) = document.select_first("head") {
     f(node.as_node())
   } else {
@@ -132,7 +132,7 @@ fn with_head<F: FnOnce(&NodeRef)>(document: &mut NodeRef, f: F) {
   }
 }
 
-fn inject_nonce(document: &mut NodeRef, selector: &str, token: &str) {
+fn inject_nonce(document: &NodeRef, selector: &str, token: &str) {
   if let Ok(scripts) = document.select(selector) {
     for target in scripts {
       let node = target.as_node();
@@ -150,7 +150,7 @@ fn inject_nonce(document: &mut NodeRef, selector: &str, token: &str) {
 
 /// Inject nonce tokens to all scripts and styles.
 pub fn inject_nonce_token(
-  document: &mut NodeRef,
+  document: &NodeRef,
   dangerous_disable_asset_csp_modification: &DisabledCspModificationKind,
 ) {
   if dangerous_disable_asset_csp_modification.can_modify("script-src") {
@@ -162,14 +162,14 @@ pub fn inject_nonce_token(
 }
 
 /// Injects a content security policy to the HTML.
-pub fn inject_csp(document: &mut NodeRef, csp: &str) {
+pub fn inject_csp(document: &NodeRef, csp: &str) {
   with_head(document, |head| {
     head.append(create_csp_meta_tag(csp));
   });
 }
 
 /// Injects a content security policy token to the HTML.
-pub fn inject_csp_token(document: &mut NodeRef) {
+pub fn inject_csp_token(document: &NodeRef) {
   inject_csp(document, CSP_TOKEN)
 }
 
@@ -239,7 +239,7 @@ impl Default for IsolationSide {
 ///
 /// Note: This function is not considered part of the stable API.
 #[cfg(feature = "isolation")]
-pub fn inject_codegen_isolation_script(document: &mut NodeRef) {
+pub fn inject_codegen_isolation_script(document: &NodeRef) {
   with_head(document, |head| {
     let script = NodeRef::new_element(QualName::new(None, ns!(html), "script".into()), None);
     script.append(NodeRef::new_text(
@@ -257,7 +257,7 @@ pub fn inject_codegen_isolation_script(document: &mut NodeRef) {
 ///
 /// Note: this does not prevent path traversal due to the isolation application expectation that it
 /// is secure.
-pub fn inline_isolation(document: &mut NodeRef, dir: &Path) {
+pub fn inline_isolation(document: &NodeRef, dir: &Path) {
   for script in document
     .select("script[src]")
     .expect("unable to parse document for scripts")
@@ -297,8 +297,8 @@ mod tests {
       "<html></html>".to_string(),
     ];
     for html in htmls {
-      let mut document = kuchiki::parse_html().one(html);
-      super::inject_csp_token(&mut document);
+      let document = kuchiki::parse_html().one(html);
+      super::inject_csp_token(&document);
       assert_eq!(
         document.to_string(),
         format!(