pub fn redact_userinfo(input: &str) -> StringExpand description
Redact URL userinfo. Non-URL inputs are returned verbatim.
Handles two shapes used across the codebase:
- Multiple full URLs joined with commas โ the historical shape
avctl doctorprints (redis://u:p@h1,redis://u:p@h2). Each segment is processed independently. - A single URL whose authority contains a cluster host list โ
Redis Cluster URI grammar
redis://user:pass@h1:port,h2:port. The whole authority is treated as one segment and userinfo is stripped before the LAST@โ which stays inside the userinfo even when the password itself contains,.
ยงExamples
use av_core::url_redact::redact_userinfo;
assert_eq!(
redact_userinfo("https://alice:secret@api.example.com/v1"),
"https://***@api.example.com/v1",
);
// Password containing `,` (a legal RFC 3986 sub-delim):
assert_eq!(
redact_userinfo("redis://u:p,w@host1:6379,host2:6379"),
"redis://***@host1:6379,host2:6379",
);
// Comma-joined list of complete URLs:
assert_eq!(
redact_userinfo("redis://u:p@h1:7000,redis://u:p@h2:7001"),
"redis://***@h1:7000,redis://***@h2:7001",
);
assert_eq!(redact_userinfo("https://api.example.com/v1"), "https://api.example.com/v1");
assert_eq!(redact_userinfo("plain text"), "plain text");