include::../description.adoc[]

== Noncompliant Code Example

----
using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Mvc;

namespace WebApplicationDotNetCore.Controllers
{
    public class RSPEC2631RegExpInjectionNoncompliantController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }

        public IActionResult Validate(string regex, string input)
        {
            bool match = Regex.IsMatch(input, regex); // Noncompliant

            return Content("Valid? " + match);
        }
    }
}
----

== Compliant Solution

----
using System;
using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Mvc;

namespace WebApplicationDotNetCore.Controllers
{
    public class RSPEC2631RegExpInjectionCompliantController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }

        public IActionResult Validate(string regex, string input)
        {
            bool match = Regex.IsMatch(input, Regex.Escape(regex)); // Compliant

            return Content("Valid? " + match);
        }
    }
}
----

include::../see.adoc[]

ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]
