Include timeout value in Regex cache key (#49352)
authorStephen Toub <stoub@microsoft.com>
Tue, 9 Mar 2021 14:41:09 +0000 (09:41 -0500)
committerGitHub <noreply@github.com>
Tue, 9 Mar 2021 14:41:09 +0000 (09:41 -0500)
commit4f67869210c4d1014255bd5ed907e78f795f9bef
tree3553a6767b0fa4ecf4e83f2d3fa16ed33da67c0f
parent17a7ed5d8b433a3b895be8f4d23ce10bed0c3ca1
Include timeout value in Regex cache key (#49352)

Static Regex methods use a cache of recently used regexes.  We currently include in the key for that cache whether a timeout value was specified, since whether there's a timeout can impact how the regex is built, but we don't currently include the actual value of the timeout.  This leads to oddities where if the same pattern, culture, and options are used with a static regex method and one non-infinite timeout, and then those exact same values are used with a different non-infinite timeout, and then original data was still in the cache, we'll end up using the previous timeout value rather than the new timeout value.  The fix is just to include the timeout itself in the key.
src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Regex.Cache.cs
src/libraries/System.Text.RegularExpressions/tests/Regex.Match.Tests.cs