From 95a7785a12c96188ab8506b14dea1cea8a454aa2 Mon Sep 17 00:00:00 2001 From: Justin Kotalik Date: Tue, 23 Aug 2016 09:57:31 -0700 Subject: [PATCH] Adds timeout to sample Regex. --- samples/RoutingSample.Web/Startup.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/samples/RoutingSample.Web/Startup.cs b/samples/RoutingSample.Web/Startup.cs index 9e00ee296e..4e5498af3f 100644 --- a/samples/RoutingSample.Web/Startup.cs +++ b/samples/RoutingSample.Web/Startup.cs @@ -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))}); }); }