diff --git a/core/lib/utils/string_convert.dart b/core/lib/utils/string_convert.dart index d105a6233..ac95df361 100644 --- a/core/lib/utils/string_convert.dart +++ b/core/lib/utils/string_convert.dart @@ -181,7 +181,7 @@ class StringConvert { input = Uri.decodeComponent(input); } - if (input.length % 4 == 0 && _base64ValidationRegex.hasMatch(input)) { + if (input.length % 4 == 0 && !input.contains(' ') && _base64ValidationRegex.hasMatch(input)) { try { input = utf8.decode(base64.decode(input)); } catch (_) {} diff --git a/core/test/utils/redos_vulnerability_test.dart b/core/test/utils/redos_vulnerability_test.dart index 1ef1f1755..672e7a3a9 100644 --- a/core/test/utils/redos_vulnerability_test.dart +++ b/core/test/utils/redos_vulnerability_test.dart @@ -474,7 +474,7 @@ void main() { test('Should handle emails with special characters - valid cases', () { // Valid emails that should be extracted successfully - final validEmailInputs = { + final validEmailInputs = { 'user+tag@example.com': 'user+tag@example.com', 'user.name@example.com': 'user.name@example.com', 'user_name@example.com': 'user_name@example.com', @@ -487,12 +487,12 @@ void main() { 'user@例え.jp': 'user@例え.jp', '${'a' * 64}@example.com': '${'a' * 64}@example.com', 'Contact us at support@example.com for help': 'support@example.com', - 'Multiple emails: alice@test.com, bob@test.org': contains('alice@test.com'), + 'Multiple emails: alice@test.com, bob@test.org': 'alice@test.com', }; for (final entry in validEmailInputs.entries) { final input = entry.key; - final expectedMatch = entry.value; + final expectedEmail = entry.value; final stopwatch = Stopwatch()..start(); final result = StringConvert.extractEmailAddress(input); @@ -501,13 +501,8 @@ void main() { expect(stopwatch.elapsedMilliseconds, lessThan(100), reason: 'Should process quickly: $input'); - if (expectedMatch is String) { - expect(result, contains(expectedMatch), - reason: 'Should extract "$expectedMatch" from: $input'); - } else { - expect(result, expectedMatch, - reason: 'Should match expected pattern from: $input'); - } + expect(result, contains(expectedEmail), + reason: 'Should extract "$expectedEmail" from: $input'); } }); @@ -658,8 +653,8 @@ void main() { StringConvert.extractEmailAddress(input); StringConvert.isTextTable('$input\n$input'); HtmlUtils.extractPlainText(input); - } catch (e) { - // It's OK if these fail, we're just testing performance + } catch (_) { + // Intentionally ignored - focus is on performance, not correctness } stopwatch.stop();