Skip to content

Commit a9cc0e4

Browse files
committed
feat(filter): Expose Redactions::redact
1 parent 4c1e2c0 commit a9cc0e4

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

crates/snapbox/src/filter/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ fn normalize_value_matches(
258258
let has_key_wildcard =
259259
exp.get(KEY_WILDCARD).and_then(|v| v.as_str()) == Some(VALUE_WILDCARD);
260260
for (actual_key, mut actual_value) in std::mem::replace(act, serde_json::Map::new()) {
261-
let actual_key = substitutions.normalize(&actual_key, "");
261+
let actual_key = substitutions.redact(&actual_key);
262262
if let Some(expected_value) = exp.get(&actual_key) {
263263
normalize_value_matches(&mut actual_value, expected_value, substitutions)
264264
} else if has_key_wildcard {

crates/snapbox/src/filter/redactions.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ impl Redactions {
9797
normalize(input, pattern, self)
9898
}
9999

100-
fn substitute(&self, input: &str) -> String {
100+
/// Apply redaction only, no pattern-dependent globs
101+
pub fn redact(&self, input: &str) -> String {
101102
let mut input = input.to_owned();
102103
replace_many(
103104
&mut input,
@@ -319,7 +320,7 @@ fn normalize(input: &str, pattern: &str, redactions: &Redactions) -> String {
319320
return input.to_owned();
320321
}
321322

322-
let input = redactions.substitute(input);
323+
let input = redactions.redact(input);
323324

324325
let mut normalized: Vec<&str> = Vec::new();
325326
let mut input_index = 0;

0 commit comments

Comments
 (0)