fixup! TF-4224 Reduce ReDoS vulnerability

This commit is contained in:
Dang Dat
2026-01-05 16:18:25 +07:00
committed by Dat H. Pham
parent 782d21d796
commit 9f1373c7e5
3 changed files with 210 additions and 55 deletions
+13
View File
@@ -21,10 +21,23 @@ class StringConvert {
);
static final _asciiArtRegex = RegExp(r'[+\-|/\\=]');
static final _namedAddressRegex = RegExp(r'''(?:(?:"([^"]+)"|'([^']+)')\s*)?<([^>]+)>''');
static final _emailLocalhostRegex = RegExp(
r'^(?:"[^"\r\n]+"|[^<>()[\]\\.,;:\s@"]+(?:\.[^<>()[\]\\.,;:\s@"]+)*)@localhost$',
);
@visibleForTesting
static RegExp get base64ValidationRegex => _base64ValidationRegex;
@visibleForTesting
static RegExp get emailLocalhostRegex => _emailLocalhostRegex;
/// Checks if the given email address is a localhost email
/// Returns true if the email ends with @localhost
static bool isEmailLocalhost(String email) {
final normalized = email.trim();
return _emailLocalhostRegex.hasMatch(normalized);
}
static String? writeEmptyToNull(String text) {
if (text.isEmpty) return null;
return text;