layerConnection function
Finds connection-string password spans in text.
Pure function; URLs without a user:password@ authority yield nothing.
Implementation
List<RedactionMatch> layerConnection(String text, RedactionConfig cfg) {
if (text.isEmpty || !text.contains('://')) return const [];
final matches = <RedactionMatch>[];
for (final m in _connectionUrl.allMatches(text)) {
// dart:core Match has no group offsets, so locate the password as the
// run between the user separator (first ':' after '://') and the last
// '@' of the matched segment (the regex guarantees both exist).
final segment = text.substring(m.start, m.end);
final userSep = segment.indexOf(':', segment.indexOf('://') + 3);
final hostSep = segment.lastIndexOf('@');
if (userSep < 0 || hostSep <= userSep) continue;
matches.add(
RedactionMatch(
start: m.start + userSep + 1,
end: m.start + hostSep,
layer: RedactionLayer.connection,
kindLabel: connectionPasswordLabel,
),
);
}
return matches;
}