From 2946edc0aee2392f56a3fc82f642b6a3e10e1853 Mon Sep 17 00:00:00 2001 From: gw79 Date: Thu, 14 May 2020 07:27:54 +0100 Subject: [PATCH] RegEx performance fix in TEHelpers (#1990) --- TechTalk.SpecFlow/Assist/TEHelpers.cs | 5 ++++- changelog.txt | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/TechTalk.SpecFlow/Assist/TEHelpers.cs b/TechTalk.SpecFlow/Assist/TEHelpers.cs index a3c91092f..686d727c7 100644 --- a/TechTalk.SpecFlow/Assist/TEHelpers.cs +++ b/TechTalk.SpecFlow/Assist/TEHelpers.cs @@ -10,6 +10,9 @@ namespace TechTalk.SpecFlow.Assist { internal static class TEHelpers { + private static readonly Regex invalidPropertyNameRegex = new Regex(InvalidPropertyNamePattern, RegexOptions.Compiled); + private const string InvalidPropertyNamePattern = @"[^\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}\p{Nd}_]"; + internal static T CreateTheInstanceWithTheDefaultConstructor(Table table, InstanceCreationOptions creationOptions) { var instance = (T)Activator.CreateInstance(typeof(T)); @@ -84,7 +87,7 @@ internal static bool MatchesThisColumnName(this string propertyName, string colu internal static string RemoveAllCharactersThatAreNotValidInAPropertyName(string name) { //Unicode groups allowed: Lu, Ll, Lt, Lm, Lo, Nl or Nd see https://msdn.microsoft.com/en-us/library/aa664670%28v=vs.71%29.aspx - return new Regex(@"[^\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}\p{Nd}_]").Replace(name, string.Empty); + return invalidPropertyNameRegex.Replace(name, string.Empty); } internal static string NormalizePropertyNameToMatchAgainstAColumnName(string name) diff --git a/changelog.txt b/changelog.txt index 9728229ab..8a5125cfc 100644 --- a/changelog.txt +++ b/changelog.txt @@ -16,6 +16,7 @@ Changes: Fixes: + Empty value for nullable enum should not throw an exception ++ RegEx performance fix in TEHelpers (Table column name validation) Fixes: