Skip to content

Commit

Permalink
one regex to rule them all
Browse files Browse the repository at this point in the history
  • Loading branch information
smklein committed Sep 3, 2024
1 parent 90c981b commit 76f256c
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions test-utils/src/dev/test_cmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,14 @@ pub fn redact_variable(input: &str) -> String {
// Replace timestamps.
//
// Format: RFC 3339 (ISO 8601)
// Example: 1970-01-01T00:00:00Z
let s = regex::Regex::new(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z")
.unwrap()
.replace_all(&s, "<REDACTED_TIMESTAMP>")
.to_string();

// Replace timestamps that have a sub-second portion.
// Example: 1970-01-01T00:00:00.000001Z
// Examples:
// 1970-01-01T00:00:00Z
// 1970-01-01T00:00:00.00001Z
//
// Note that depending on the amount of trailing zeros,
// this value can have different widths. However, "<REDACTED_TIMESTAMP>"
// has a deterministic width, so that's used instead.
let s = regex::Regex::new(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+Z")
let s = regex::Regex::new(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z")
.unwrap()
.replace_all(&s, "<REDACTED_TIMESTAMP>")
.to_string();
Expand Down

0 comments on commit 76f256c

Please sign in to comment.