fixup! TF-4224 Reduce ReDoS vulnerability

This commit is contained in:
Dang Dat
2025-12-24 15:37:48 +07:00
committed by Dat H. Pham
parent a8f90ec700
commit 3d08fc9e5f
2 changed files with 7 additions and 17 deletions
+3 -17
View File
@@ -361,23 +361,9 @@ void main() {
group('Regex initialization optimization', () {
test('regex patterns should be reused, not recreated', () {
// This test verifies that regex patterns are static and reused
// We can't directly test if they're the same object, but we can
// verify performance doesn't degrade with multiple calls
const iterations = 1000;
final stopwatch = Stopwatch()..start();
for (var i = 0; i < iterations; i++) {
StringConvert.isTextTable('| a | b |\n|---|---|\n| c | d |');
HtmlUtils.wrapPlainTextLinks('<p>https://example.com</p>');
StringConvert.extractEmailAddress('test@example.com, test2@example.com');
}
stopwatch.stop();
// If regex patterns were being recreated each time, this would be much slower
expect(stopwatch.elapsedMilliseconds, lessThan(500),
reason: 'Multiple calls should be fast due to regex reuse');
final regex1 = StringConvert.base64ValidationRegex;
final regex2 = StringConvert.base64ValidationRegex;
expect(identical(regex1, regex2), true);
});
});
});