Added timeout to regex
This commit is contained in:
parent
e2881b0eca
commit
88f4153fd9
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
|
||||||
private static readonly Regex _fullNameSanitizer = new Regex(
|
private static readonly Regex _fullNameSanitizer = new Regex(
|
||||||
@", [A-Za-z\.]+, Version=\d+\.\d+\.\d+\.\d+, Culture=neutral, PublicKeyToken=\w+",
|
@", [A-Za-z\.]+, Version=\d+\.\d+\.\d+\.\d+, Culture=neutral, PublicKeyToken=\w+",
|
||||||
RegexOptions.ExplicitCapture,
|
RegexOptions.ExplicitCapture,
|
||||||
matchTimeout: TimeSpan.FromSeconds(10));
|
Constants.RegexMatchTimeout);
|
||||||
|
|
||||||
private static readonly TypeInfo TagHelperTypeInfo = typeof(ITagHelper).GetTypeInfo();
|
private static readonly TypeInfo TagHelperTypeInfo = typeof(ITagHelper).GetTypeInfo();
|
||||||
private IEnumerable<IPropertyInfo> _properties;
|
private IEnumerable<IPropertyInfo> _properties;
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,10 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
|
||||||
// Any lowercase letter followed by an uppercase letter: a(A)
|
// Any lowercase letter followed by an uppercase letter: a(A)
|
||||||
// Each match is then prefixed by a "-" via the ToHtmlCase method.
|
// Each match is then prefixed by a "-" via the ToHtmlCase method.
|
||||||
private static readonly Regex HtmlCaseRegex =
|
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());
|
private static readonly ITypeInfo StringTypeInfo = new RuntimeTypeInfo(typeof(string).GetTypeInfo());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -239,7 +239,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
|
||||||
// string. We also replace any '*' or '?' characters with regex to match appropriate content.
|
// string. We also replace any '*' or '?' characters with regex to match appropriate content.
|
||||||
// '*' matches 0 or more characters lazily and '?' matches 1 character.
|
// '*' matches 0 or more characters lazily and '?' matches 1 character.
|
||||||
var pattern = "^" + escaped.Replace(@"\?", ".").Replace(@"\*", ".*?") + "$";
|
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);
|
return regex.IsMatch(descriptor.TypeName);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue