Strip credentials from URLs before text reaches the log file. `text` with every URL's credentials removed: everything up to the last `@` becomes `***@`, and the query and fragment are dropped. Remote errors name the URL they failed on, remote URLs can carry credentials in either place, and an "invalid URL" error may quote one too malformed to parse, so this over-redacts rather than parsing.
(text: &str)
| 6 | /// place, and an "invalid URL" error may quote one too malformed to parse, |
| 7 | /// so this over-redacts rather than parsing. |
| 8 | pub(crate) fn urls(text: &str) -> String { |
| 9 | let mut out = String::with_capacity(text.len()); |
| 10 | let mut rest = text; |
| 11 | while let Some(at) = rest.find("://") { |
| 12 | let (before, after) = rest.split_at(at + "://".len()); |
| 13 | out.push_str(before); |
| 14 | let end = after.find(char::is_whitespace).unwrap_or(after.len()); |
| 15 | let (url, tail) = after.split_at(end); |
| 16 | push_redacted(&mut out, url); |
| 17 | rest = tail; |
| 18 | } |
| 19 | out.push_str(rest); |
| 20 | out |
| 21 | } |
| 22 | |
| 23 | /// Push `url` (what follows `scheme://`, up to whitespace) without its |
| 24 | /// credentials. |
no test coverage detected