Skip to content

Commit 8db26bd

Browse files
fix(core): Clippy fixes. (#7869)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent c1ec0f1 commit 8db26bd

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

core/tauri-codegen/src/context.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ fn map_core_assets(
4040
if path.extension() == Some(OsStr::new("html")) {
4141
#[allow(clippy::collapsible_if)]
4242
if csp {
43-
let mut document = parse_html(String::from_utf8_lossy(input).into_owned());
43+
let document = parse_html(String::from_utf8_lossy(input).into_owned());
4444

4545
if target == Target::Linux {
46-
::tauri_utils::html::inject_csp_token(&mut document);
46+
::tauri_utils::html::inject_csp_token(&document);
4747
}
4848

49-
inject_nonce_token(&mut document, &dangerous_disable_asset_csp_modification);
49+
inject_nonce_token(&document, &dangerous_disable_asset_csp_modification);
5050

5151
if dangerous_disable_asset_csp_modification.can_modify("script-src") {
5252
if let Ok(inline_script_elements) = document.select("script:not(empty)") {
@@ -97,14 +97,13 @@ fn map_isolation(
9797
) -> impl Fn(&AssetKey, &Path, &mut Vec<u8>, &mut CspHashes) -> Result<(), EmbeddedAssetsError> {
9898
move |_key, path, input, _csp_hashes| {
9999
if path.extension() == Some(OsStr::new("html")) {
100-
let mut isolation_html =
101-
tauri_utils::html::parse(String::from_utf8_lossy(input).into_owned());
100+
let isolation_html = tauri_utils::html::parse(String::from_utf8_lossy(input).into_owned());
102101

103102
// this is appended, so no need to reverse order it
104-
tauri_utils::html::inject_codegen_isolation_script(&mut isolation_html);
103+
tauri_utils::html::inject_codegen_isolation_script(&isolation_html);
105104

106105
// temporary workaround for windows not loading assets
107-
tauri_utils::html::inline_isolation(&mut isolation_html, &dir);
106+
tauri_utils::html::inline_isolation(&isolation_html, &dir);
108107

109108
*input = isolation_html.to_string().as_bytes().to_vec()
110109
}

core/tauri-utils/src/html.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub fn parse(html: String) -> NodeRef {
119119
kuchiki::parse_html().one(html)
120120
}
121121

122-
fn with_head<F: FnOnce(&NodeRef)>(document: &mut NodeRef, f: F) {
122+
fn with_head<F: FnOnce(&NodeRef)>(document: &NodeRef, f: F) {
123123
if let Ok(ref node) = document.select_first("head") {
124124
f(node.as_node())
125125
} else {
@@ -132,7 +132,7 @@ fn with_head<F: FnOnce(&NodeRef)>(document: &mut NodeRef, f: F) {
132132
}
133133
}
134134

135-
fn inject_nonce(document: &mut NodeRef, selector: &str, token: &str) {
135+
fn inject_nonce(document: &NodeRef, selector: &str, token: &str) {
136136
if let Ok(scripts) = document.select(selector) {
137137
for target in scripts {
138138
let node = target.as_node();
@@ -150,7 +150,7 @@ fn inject_nonce(document: &mut NodeRef, selector: &str, token: &str) {
150150

151151
/// Inject nonce tokens to all scripts and styles.
152152
pub fn inject_nonce_token(
153-
document: &mut NodeRef,
153+
document: &NodeRef,
154154
dangerous_disable_asset_csp_modification: &DisabledCspModificationKind,
155155
) {
156156
if dangerous_disable_asset_csp_modification.can_modify("script-src") {
@@ -162,14 +162,14 @@ pub fn inject_nonce_token(
162162
}
163163

164164
/// Injects a content security policy to the HTML.
165-
pub fn inject_csp(document: &mut NodeRef, csp: &str) {
165+
pub fn inject_csp(document: &NodeRef, csp: &str) {
166166
with_head(document, |head| {
167167
head.append(create_csp_meta_tag(csp));
168168
});
169169
}
170170

171171
/// Injects a content security policy token to the HTML.
172-
pub fn inject_csp_token(document: &mut NodeRef) {
172+
pub fn inject_csp_token(document: &NodeRef) {
173173
inject_csp(document, CSP_TOKEN)
174174
}
175175

@@ -239,7 +239,7 @@ impl Default for IsolationSide {
239239
///
240240
/// Note: This function is not considered part of the stable API.
241241
#[cfg(feature = "isolation")]
242-
pub fn inject_codegen_isolation_script(document: &mut NodeRef) {
242+
pub fn inject_codegen_isolation_script(document: &NodeRef) {
243243
with_head(document, |head| {
244244
let script = NodeRef::new_element(QualName::new(None, ns!(html), "script".into()), None);
245245
script.append(NodeRef::new_text(
@@ -257,7 +257,7 @@ pub fn inject_codegen_isolation_script(document: &mut NodeRef) {
257257
///
258258
/// Note: this does not prevent path traversal due to the isolation application expectation that it
259259
/// is secure.
260-
pub fn inline_isolation(document: &mut NodeRef, dir: &Path) {
260+
pub fn inline_isolation(document: &NodeRef, dir: &Path) {
261261
for script in document
262262
.select("script[src]")
263263
.expect("unable to parse document for scripts")
@@ -297,8 +297,8 @@ mod tests {
297297
"<html></html>".to_string(),
298298
];
299299
for html in htmls {
300-
let mut document = kuchiki::parse_html().one(html);
301-
super::inject_csp_token(&mut document);
300+
let document = kuchiki::parse_html().one(html);
301+
super::inject_csp_token(&document);
302302
assert_eq!(
303303
document.to_string(),
304304
format!(

0 commit comments

Comments
 (0)