Added timeout to regex
This commit is contained in:
parent
87360d861f
commit
ee9945f06d
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Microsoft.AspNet.Builder;
|
using Microsoft.AspNet.Builder;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
|
|
@ -49,7 +50,11 @@ namespace RoutingSample.Web
|
||||||
routeBuilder.MapRoute("regexRoute",
|
routeBuilder.MapRoute("regexRoute",
|
||||||
"api/r2constraint/{controller}",
|
"api/r2constraint/{controller}",
|
||||||
new { foo = "Bar2" },
|
new { foo = "Bar2" },
|
||||||
new { controller = new RegexRouteConstraint(new Regex("^(my.*)$")) });
|
new
|
||||||
|
{
|
||||||
|
controller = new RegexRouteConstraint(
|
||||||
|
new Regex("^(my.*)$", RegexOptions.None, TimeSpan.FromSeconds(10)))
|
||||||
|
});
|
||||||
|
|
||||||
routeBuilder.MapRoute("parameterConstraintRoute",
|
routeBuilder.MapRoute("parameterConstraintRoute",
|
||||||
"api/{controller}/{*extra}",
|
"api/{controller}/{*extra}",
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ namespace Microsoft.AspNet.Routing.Constraints
|
||||||
{
|
{
|
||||||
public class RegexRouteConstraint : IRouteConstraint
|
public class RegexRouteConstraint : IRouteConstraint
|
||||||
{
|
{
|
||||||
|
private static readonly TimeSpan RegexMatchTimeout = TimeSpan.FromSeconds(10);
|
||||||
|
|
||||||
public RegexRouteConstraint([NotNull] Regex regex)
|
public RegexRouteConstraint([NotNull] Regex regex)
|
||||||
{
|
{
|
||||||
Constraint = regex;
|
Constraint = regex;
|
||||||
|
|
@ -19,7 +21,10 @@ namespace Microsoft.AspNet.Routing.Constraints
|
||||||
|
|
||||||
public RegexRouteConstraint([NotNull] string regexPattern)
|
public RegexRouteConstraint([NotNull] string regexPattern)
|
||||||
{
|
{
|
||||||
Constraint = new Regex(regexPattern, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
|
Constraint = new Regex(
|
||||||
|
regexPattern,
|
||||||
|
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase,
|
||||||
|
RegexMatchTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Regex Constraint { get; private set; }
|
public Regex Constraint { get; private set; }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue