Adds timeout to sample Regex.

This commit is contained in:
Justin Kotalik 2016-08-23 09:57:31 -07:00
parent 714c3d6659
commit 95a7785a12
1 changed files with 4 additions and 3 deletions

View File

@ -1,9 +1,8 @@
// 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.
using System.Globalization;
using System;
using System.Text.RegularExpressions;
using System.Threading;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
@ -15,6 +14,8 @@ namespace RoutingSample.Web
{
public class Startup
{
private static readonly TimeSpan RegexMatchTimeout = TimeSpan.FromSeconds(10);
public void ConfigureServices(IServiceCollection services)
{
services.AddRouting();
@ -37,7 +38,7 @@ namespace RoutingSample.Web
name: "AllVerbs",
template: "api/all/{name}/{lastName?}",
defaults: new { lastName = "Doe" },
constraints: new { lastName = new RegexRouteConstraint(new Regex("[a-zA-Z]{3}")) });
constraints: new { lastName = new RegexRouteConstraint(new Regex("[a-zA-Z]{3}", RegexOptions.CultureInvariant, RegexMatchTimeout))});
});
}