fixup! TF-4224 Reduce ReDoS vulnerability

This commit is contained in:
Dang Dat
2025-12-24 15:05:45 +07:00
committed by Dat H. Pham
parent 86dec27d67
commit a8f90ec700
3 changed files with 39 additions and 12 deletions
+26
View File
@@ -815,6 +815,32 @@ void main() {
]),
);
});
test('Does not corrupt plain text that looks like base64', () {
// "useruser" is 8 chars (multiple of 4) and fits the base64 regex.
// base64.decode("useruser") produces random bytes.
const input = 'useruser';
final result = StringConvert.extractNamedAddresses(input);
expect(result.first.address, equals('useruser'));
});
test('Handles brackets with no name', () {
const input = '<only-email@example.com>';
final result = StringConvert.extractNamedAddresses(input);
expect(result.first.name, isEmpty);
expect(result.first.address, equals('only-email@example.com'));
});
test('Handles names containing commas', () {
const input =
'"Doe, John" <john@example.com>, "Smith, Jane" <jane@example.com>';
final result = StringConvert.extractNamedAddresses(input);
expect(result[0].name, equals('Doe, John'));
expect(result[1].name, equals('Smith, Jane'));
});
test('Handles malformed input gracefully', () {
const input = '"Unclosed Quote <email@example.com>';
final result = StringConvert.extractNamedAddresses(input);
// Ensure it doesn't crash and returns at least the email
expect(result, isNotEmpty);
});
});
group('StringConvert.convertHtmlContentToTextContent', () {