File tree Expand file tree Collapse file tree 1 file changed +18
-6
lines changed
Expand file tree Collapse file tree 1 file changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -1333,11 +1333,23 @@ async def handler(request: Request) -> Response:
13331333
13341334def test_regex_performance () -> None :
13351335 value = "0" * 54773 + "\\ 0=a"
1336- start = time .perf_counter ()
1337- matches = _HEADER_PAIRS_PATTERN .findall (value )
1338- end = time .perf_counter ()
13391336
1340- # If this is taking more than 10ms, there's probably a performance/ReDoS issue.
1341- assert (end - start ) < 0.01
1337+ best_time = float ("inf" )
1338+ best_matches : list [tuple [str , str ]] = []
1339+
1340+ for _ in range (5 ):
1341+ start = time .perf_counter ()
1342+ matches = _HEADER_PAIRS_PATTERN .findall (value )
1343+ elapsed = time .perf_counter () - start
1344+
1345+ if elapsed < best_time :
1346+ best_time = elapsed
1347+ best_matches = matches
1348+
1349+ # Relaxed for CI/platform variability (e.g., macOS runners ~40-50ms observed)
1350+ assert (
1351+ best_time < 0.1
1352+ ), f"Regex took { best_time * 1000 :.1f} ms, expected <100ms - potential ReDoS issue"
1353+
13421354 # This example probably shouldn't produce a match either.
1343- assert not matches
1355+ assert not best_matches
You can’t perform that action at this time.
0 commit comments