Added timeout to regex

This commit is contained in:
Ajay Bhargav Baaskaran 2015-09-10 11:24:13 -07:00
parent e2881b0eca
commit 88f4153fd9
4 changed files with 18 additions and 3 deletions

View File

@ -0,0 +1,12 @@
// 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;
namespace Microsoft.AspNet.Razor.Runtime
{
internal static class Constants
{
public static readonly TimeSpan RegexMatchTimeout = TimeSpan.FromSeconds(10);
}
}

View File

@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
private static readonly Regex _fullNameSanitizer = new Regex(
@", [A-Za-z\.]+, Version=\d+\.\d+\.\d+\.\d+, Culture=neutral, PublicKeyToken=\w+",
RegexOptions.ExplicitCapture,
matchTimeout: TimeSpan.FromSeconds(10));
Constants.RegexMatchTimeout);
private static readonly TypeInfo TagHelperTypeInfo = typeof(ITagHelper).GetTypeInfo();
private IEnumerable<IPropertyInfo> _properties;

View File

@ -26,7 +26,10 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
// Any lowercase letter followed by an uppercase letter: a(A)
// Each match is then prefixed by a "-" via the ToHtmlCase method.
private static readonly Regex HtmlCaseRegex =
new Regex("(?<!^)((?<=[a-zA-Z0-9])[A-Z][a-z])|((?<=[a-z])[A-Z])", RegexOptions.None);
new Regex(
"(?<!^)((?<=[a-zA-Z0-9])[A-Z][a-z])|((?<=[a-z])[A-Z])",
RegexOptions.None,
Constants.RegexMatchTimeout);
private static readonly ITypeInfo StringTypeInfo = new RuntimeTypeInfo(typeof(string).GetTypeInfo());

View File

@ -239,7 +239,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
// string. We also replace any '*' or '?' characters with regex to match appropriate content.
// '*' matches 0 or more characters lazily and '?' matches 1 character.
var pattern = "^" + escaped.Replace(@"\?", ".").Replace(@"\*", ".*?") + "$";
var regex = new Regex(pattern, RegexOptions.Singleline);
var regex = new Regex(pattern, RegexOptions.Singleline, Constants.RegexMatchTimeout);
return regex.IsMatch(descriptor.TypeName);
}