
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
31 lines
860 B
Plaintext
31 lines
860 B
Plaintext
include::../description.adoc[]
|
|
|
|
== Sensitive Code Example
|
|
|
|
[source,csharp]
|
|
----
|
|
public void RegexPattern(string input)
|
|
{
|
|
var emailPattern = new Regex(".+@.+", RegexOptions.None);
|
|
var isNumber = Regex.IsMatch(input, "[0-9]+");
|
|
var isLetterA = Regex.IsMatch(input, "(a+)+");
|
|
}
|
|
----
|
|
|
|
== Compliant Solution
|
|
|
|
[source,csharp]
|
|
----
|
|
public void RegexPattern(string input)
|
|
{
|
|
var emailPattern = new Regex(".+@.+", RegexOptions.None, TimeSpan.FromMilliseconds(100));
|
|
var isNumber = Regex.IsMatch(input, "[0-9]+", RegexOptions.None, TimeSpan.FromMilliseconds(100));
|
|
var isLetterA = Regex.IsMatch(input, "(a+)+", RegexOptions.NonBacktracking); // .Net 7 and above
|
|
AppDomain.CurrentDomain.SetData("REGEX_DEFAULT_MATCH_TIMEOUT", TimeSpan.FromMilliseconds(100)); // process-wide setting
|
|
}
|
|
----
|
|
|
|
include::../see.adoc[]
|
|
|
|
include::../rspecator.adoc[]
|