redactUrlUserinfo function

String redactUrlUserinfo(
  1. String text
)

text with the userinfo of every URL it contains replaced by ***.

scheme://userinfo@host/rest becomes scheme://***@host/rest; the scheme, host, path and the rest of the text are kept, including when the URL is part of a larger argument or of a line. Percent-encoded userinfo is replaced as written. The scp-like user@host:path spelling carries no scheme and is left unchanged.

Implementation

String redactUrlUserinfo(String text) {
  return text.replaceAllMapped(
    _userinfoPattern,
    (Match match) => '${match.group(1)}***@',
  );
}