Skip to content

Commit c3706e2

Browse files
mostafawoodruffw
andauthored
Add Fix for cache-poisoning audit rule (#923)
Co-authored-by: William Woodruff <[email protected]>
1 parent cc92548 commit c3706e2

14 files changed

+327
-43
lines changed

crates/yamlpatch/src/lib.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,7 @@ fn apply_single_patch(
327327
Some(idx) => (idx + bias, idx + bias + from.len()),
328328
None => {
329329
return Err(Error::InvalidOperation(format!(
330-
"no match for '{}' in feature",
331-
from
330+
"no match for '{from}' in feature"
332331
)));
333332
}
334333
};
@@ -437,8 +436,7 @@ fn apply_single_patch(
437436
let style = Style::from_feature(&existing_feature, document);
438437
if !matches!(style, Style::BlockMapping | Style::FlowMapping) {
439438
return Err(Error::InvalidOperation(format!(
440-
"can't perform merge against non-mapping at {:?}",
441-
existing_key_route
439+
"can't perform merge against non-mapping at {existing_key_route:?}"
442440
)));
443441
}
444442

@@ -465,8 +463,7 @@ fn apply_single_patch(
465463
)
466464
.map_err(|e| {
467465
Error::InvalidOperation(format!(
468-
"MergeInto: failed to parse existing mapping at {:?}: {e}",
469-
existing_key_route
466+
"MergeInto: failed to parse existing mapping at {existing_key_route:?}: {e}"
470467
))
471468
})?;
472469

@@ -500,8 +497,7 @@ fn apply_single_patch(
500497
// The key exists, but has an empty body.
501498
// TODO: Support this.
502499
Ok(None) => Err(Error::InvalidOperation(format!(
503-
"MergeInto: cannot merge into empty key at {:?}",
504-
existing_key_route
500+
"MergeInto: cannot merge into empty key at {existing_key_route:?}"
505501
))),
506502
// The key does not exist.
507503
Err(Error::Query(yamlpath::QueryError::ExhaustedMapping(_))) => apply_single_patch(
@@ -632,8 +628,7 @@ pub fn serialize_flow(value: &serde_yaml::Value) -> Result<String, Error> {
632628
}
633629
if !matches!(key, serde_yaml::Value::String(_)) {
634630
return Err(Error::InvalidOperation(format!(
635-
"mapping keys must be strings, found: {:?}",
636-
key
631+
"mapping keys must be strings, found: {key:?}"
637632
)));
638633
}
639634
serialize_inner(key, buf)?;
@@ -649,8 +644,7 @@ pub fn serialize_flow(value: &serde_yaml::Value) -> Result<String, Error> {
649644
Ok(())
650645
}
651646
serde_yaml::Value::Tagged(tagged_value) => Err(Error::InvalidOperation(format!(
652-
"cannot serialize tagged value: {:?}",
653-
tagged_value
647+
"cannot serialize tagged value: {tagged_value:?}"
654648
))),
655649
}
656650
}
@@ -961,7 +955,7 @@ fn apply_value_replacement(
961955
if string_content.contains('\n') {
962956
// For multiline literal blocks, use the raw string content
963957
let leading_whitespace = extract_leading_whitespace(doc, feature);
964-
let content_indent = format!("{} ", leading_whitespace); // Key indent + 2 spaces for content
958+
let content_indent = format!("{leading_whitespace} "); // Key indent + 2 spaces for content
965959

966960
// Format as: key: |\n content\n more content
967961
let indented_content = string_content
@@ -1027,15 +1021,15 @@ fn handle_flow_mapping_value_replacement(
10271021
if value_part.is_empty() {
10281022
// Case: { key: } -> { key: value }
10291023
let key_part = before_colon.trim_start_matches('{').trim();
1030-
Ok(format!("{{ {}: {} }}", key_part, val_str))
1024+
Ok(format!("{{ {key_part}: {val_str} }}"))
10311025
} else {
10321026
// Case: { key: oldvalue } -> { key: newvalue }
10331027
let key_part = before_colon.trim_start_matches('{').trim();
1034-
Ok(format!("{{ {}: {} }}", key_part, val_str))
1028+
Ok(format!("{{ {key_part}: {val_str} }}"))
10351029
}
10361030
} else {
10371031
// Case 2: { key } - no colon, bare key -> { key: value }
10381032
let key_part = trimmed.trim_start_matches('{').trim_end_matches('}').trim();
1039-
Ok(format!("{{ {}: {} }}", key_part, val_str))
1033+
Ok(format!("{{ {key_part}: {val_str} }}"))
10401034
}
10411035
}

0 commit comments

Comments
 (0)