Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 9713ca9

Browse files
committed
Update IsValidVarName/IsValidVarRef
1 parent 3e5a840 commit 9713ca9

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/ServiceStack.Text/StringExtensions.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -853,10 +853,13 @@ public static bool EndsWithInvariant(this string str, string endsWith)
853853
return str.EndsWith(endsWith, PclExport.Instance.InvariantComparison);
854854
}
855855

856-
private static readonly Regex InvalidVarCharsRegex = new Regex(@"[^A-Za-z0-9_]", RegexOptions.Compiled);
857-
private static readonly Regex InvalidVarRefCharsRegex = new Regex(@"[^A-Za-z0-9._]", RegexOptions.Compiled);
858-
private static readonly Regex SplitCamelCaseRegex = new Regex("([A-Z]|[0-9]+)", RegexOptions.Compiled);
859-
private static readonly Regex HttpRegex = new Regex(@"^http://",
856+
private static readonly Regex InvalidVarCharsRegex = new(@"[^A-Za-z0-9_]", RegexOptions.Compiled);
857+
private static readonly Regex ValidVarCharsRegex = new(@"^[A-Za-z0-9_]+$", RegexOptions.Compiled);
858+
private static readonly Regex InvalidVarRefCharsRegex = new(@"[^A-Za-z0-9._]", RegexOptions.Compiled);
859+
private static readonly Regex ValidVarRefCharsRegex = new(@"^[A-Za-z0-9._]+$", RegexOptions.Compiled);
860+
861+
private static readonly Regex SplitCamelCaseRegex = new("([A-Z]|[0-9]+)", RegexOptions.Compiled);
862+
private static readonly Regex HttpRegex = new(@"^http://",
860863
PclExport.Instance.RegexOptions | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
861864

862865
public static T ToEnum<T>(this string value)
@@ -951,8 +954,8 @@ public static bool ContainsAny(this string text, string[] testMatches, StringCom
951954
return false;
952955
}
953956

954-
public static bool IsValidVarName(this string name) => InvalidVarCharsRegex.IsMatch(name);
955-
public static bool IsValidVarRef(this string name) => InvalidVarRefCharsRegex.IsMatch(name);
957+
public static bool IsValidVarName(this string name) => ValidVarCharsRegex.IsMatch(name);
958+
public static bool IsValidVarRef(this string name) => ValidVarRefCharsRegex.IsMatch(name);
956959

957960
public static string SafeVarName(this string text) => !string.IsNullOrEmpty(text)
958961
? InvalidVarCharsRegex.Replace(text, "_") : null;

0 commit comments

Comments
 (0)