From bb3127b1f20b48a14c1e91b1b7476421592cbd14 Mon Sep 17 00:00:00 2001 From: Dan Moseley Date: Tue, 21 Apr 2026 14:56:15 -0600 Subject: [PATCH] Fix flaky RegularExpressionAttribute timeout test The test used a 28-character input with a 1ms timeout, but regex engine improvements allowed completion before the timeout check fired, causing IsValid to return false instead of throwing RegexMatchTimeoutException. Use 100 characters to ensure the exponential backtracking exceeds the timeout. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../DataAnnotations/RegularExpressionAttributeTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/RegularExpressionAttributeTests.cs b/src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/RegularExpressionAttributeTests.cs index 45a9da9712f262..99a9831a3e6f9e 100644 --- a/src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/RegularExpressionAttributeTests.cs +++ b/src/libraries/System.ComponentModel.Annotations/tests/System/ComponentModel/DataAnnotations/RegularExpressionAttributeTests.cs @@ -78,7 +78,7 @@ public static void Validate_InvalidMatchTimeoutInMilliseconds_ThrowsArgumentOutO public static void Validate_MatchingTimesOut_ThrowsRegexMatchTimeoutException() { RegularExpressionAttribute attribute = new RegularExpressionAttribute("(a[ab]+)+$") { MatchTimeoutInMilliseconds = 1 }; - Assert.Throws(() => attribute.Validate("aaaaaaaaaaaaaaaaaaaaaaaaaaaa>", new ValidationContext(new object()))); + Assert.Throws(() => attribute.Validate(new string('a', 100) + ">", new ValidationContext(new object()))); } [Fact]