tryParse static method
Parses raw, returning null when its scheme is not allowed.
Allowlist: http, https, mailto, tel and relative URLs
(/, ./, #, ?, bare paths). Blocked: everything else, including
javascript:, data:, vbscript:.
Implementation
static SafeUrl? tryParse(String raw) {
final cleaned = raw.replaceAll(_controlChars, '').trim();
if (cleaned.isEmpty) {
return null;
}
final scheme = _schemePattern.firstMatch(cleaned);
if (scheme != null &&
!_allowedSchemes.contains(scheme.group(1)!.toLowerCase())) {
return null;
}
return _SafeUrl(cleaned);
}