Skip to content

Commit

Permalink
feat(filter): Expose Redactions::redact
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed May 23, 2024
1 parent 4c1e2c0 commit a9cc0e4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/snapbox/src/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ fn normalize_value_matches(
let has_key_wildcard =
exp.get(KEY_WILDCARD).and_then(|v| v.as_str()) == Some(VALUE_WILDCARD);
for (actual_key, mut actual_value) in std::mem::replace(act, serde_json::Map::new()) {
let actual_key = substitutions.normalize(&actual_key, "");
let actual_key = substitutions.redact(&actual_key);
if let Some(expected_value) = exp.get(&actual_key) {
normalize_value_matches(&mut actual_value, expected_value, substitutions)
} else if has_key_wildcard {
Expand Down
5 changes: 3 additions & 2 deletions crates/snapbox/src/filter/redactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ impl Redactions {
normalize(input, pattern, self)
}

fn substitute(&self, input: &str) -> String {
/// Apply redaction only, no pattern-dependent globs
pub fn redact(&self, input: &str) -> String {
let mut input = input.to_owned();
replace_many(
&mut input,
Expand Down Expand Up @@ -319,7 +320,7 @@ fn normalize(input: &str, pattern: &str, redactions: &Redactions) -> String {
return input.to_owned();
}

let input = redactions.substitute(input);
let input = redactions.redact(input);

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

0 comments on commit a9cc0e4

Please sign in to comment.