Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[csharp-netcore] Made escaped regex not be literal strings #15107

Merged
merged 1 commit into from
Apr 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
made escaped regex be not literal strings
devhl-labs committed Apr 1, 2023
commit e91137be4aa15390c31adacbf4f4b63cd8209f33
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ namespace {{packageName}}.Client
/// <returns>Filename</returns>
public static string SanitizeFilename(string filename)
{
Match match = Regex.Match(filename, @".*[/\\](.*)$");
Match match = Regex.Match(filename, ".*[/\\](.*)$");
return match.Success ? match.Groups[1].Value : filename;
}

Original file line number Diff line number Diff line change
@@ -96,7 +96,7 @@ namespace {{packageName}}.{{clientPackage}}
/// <returns>Filename</returns>
public static string SanitizeFilename(string filename)
{
Match match = Regex.Match(filename, @".*[/\\](.*)$");
Match match = Regex.Match(filename, ".*[/\\](.*)$");
return match.Success ? match.Groups[1].Value : filename;
}

Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@
{{#pattern}}
{{^isByteArray}}
// {{{name}}} ({{{dataType}}}) pattern
Regex regex{{{name}}} = new Regex(@"{{{vendorExtensions.x-regex}}}"{{#vendorExtensions.x-modifiers}}{{#-first}}, {{/-first}}RegexOptions.{{{.}}}{{^-last}} | {{/-last}}{{/vendorExtensions.x-modifiers}});
Regex regex{{{name}}} = new Regex("{{{vendorExtensions.x-regex}}}"{{#vendorExtensions.x-modifiers}}{{#-first}}, {{/-first}}RegexOptions.{{{.}}}{{^-last}} | {{/-last}}{{/vendorExtensions.x-modifiers}});
if (false == regex{{{name}}}.Match(this.{{{name}}}{{#isUuid}}.ToString(){{/isUuid}}).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for {{{name}}}, must match a pattern of " + regex{{{name}}}, new [] { "{{{name}}}" });
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ static ClientUtils()
/// <returns>Filename</returns>
public static string SanitizeFilename(string filename)
{
Match match = Regex.Match(filename, @".*[/\\](.*)$");
Match match = Regex.Match(filename, ".*[/\\](.*)$");
return match.Success ? match.Groups[1].Value : filename;
}

Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ static ClientUtils()
/// <returns>Filename</returns>
public static string SanitizeFilename(string filename)
{
Match match = Regex.Match(filename, @".*[/\\](.*)$");
Match match = Regex.Match(filename, ".*[/\\](.*)$");
return match.Success ? match.Groups[1].Value : filename;
}

Original file line number Diff line number Diff line change
@@ -183,14 +183,14 @@ public override int GetHashCode()
public IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> Validate(ValidationContext validationContext)
{
// Cultivar (string) pattern
Regex regexCultivar = new Regex(@"^[a-zA-Z\\s]*$", RegexOptions.CultureInvariant);
Regex regexCultivar = new Regex("^[a-zA-Z\\s]*$", RegexOptions.CultureInvariant);
if (false == regexCultivar.Match(this.Cultivar).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Cultivar, must match a pattern of " + regexCultivar, new [] { "Cultivar" });
}

// Origin (string) pattern
Regex regexOrigin = new Regex(@"^[A-Z\\s]*$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
Regex regexOrigin = new Regex("^[A-Z\\s]*$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
if (false == regexOrigin.Match(this.Origin).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Origin, must match a pattern of " + regexOrigin, new [] { "Origin" });
Original file line number Diff line number Diff line change
@@ -796,7 +796,7 @@ public override int GetHashCode()
}

// String (string) pattern
Regex regexString = new Regex(@"[a-z]", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
Regex regexString = new Regex("[a-z]", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
if (false == regexString.Match(this.String).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for String, must match a pattern of " + regexString, new [] { "String" });
@@ -815,14 +815,14 @@ public override int GetHashCode()
}

// PatternWithDigits (string) pattern
Regex regexPatternWithDigits = new Regex(@"^\\d{10}$", RegexOptions.CultureInvariant);
Regex regexPatternWithDigits = new Regex("^\\d{10}$", RegexOptions.CultureInvariant);
if (false == regexPatternWithDigits.Match(this.PatternWithDigits).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for PatternWithDigits, must match a pattern of " + regexPatternWithDigits, new [] { "PatternWithDigits" });
}

// PatternWithDigitsAndDelimiter (string) pattern
Regex regexPatternWithDigitsAndDelimiter = new Regex(@"^image_\\d{1,3}$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
Regex regexPatternWithDigitsAndDelimiter = new Regex("^image_\\d{1,3}$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
if (false == regexPatternWithDigitsAndDelimiter.Match(this.PatternWithDigitsAndDelimiter).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for PatternWithDigitsAndDelimiter, must match a pattern of " + regexPatternWithDigitsAndDelimiter, new [] { "PatternWithDigitsAndDelimiter" });
Original file line number Diff line number Diff line change
@@ -253,7 +253,7 @@ public override int GetHashCode()
public IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> Validate(ValidationContext validationContext)
{
// UuidWithPattern (Guid) pattern
Regex regexUuidWithPattern = new Regex(@"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", RegexOptions.CultureInvariant);
Regex regexUuidWithPattern = new Regex("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", RegexOptions.CultureInvariant);
if (false == regexUuidWithPattern.Match(this.UuidWithPattern.ToString()).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for UuidWithPattern, must match a pattern of " + regexUuidWithPattern, new [] { "UuidWithPattern" });
Original file line number Diff line number Diff line change
@@ -100,7 +100,7 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
/// <returns>Filename</returns>
public static string SanitizeFilename(string filename)
{
Match match = Regex.Match(filename, @".*[/\\](.*)$");
Match match = Regex.Match(filename, ".*[/\\](.*)$");
return match.Success ? match.Groups[1].Value : filename;
}

Original file line number Diff line number Diff line change
@@ -82,14 +82,14 @@ public override string ToString()
public IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> Validate(ValidationContext validationContext)
{
// Cultivar (string) pattern
Regex regexCultivar = new Regex(@"^[a-zA-Z\\s]*$", RegexOptions.CultureInvariant);
Regex regexCultivar = new Regex("^[a-zA-Z\\s]*$", RegexOptions.CultureInvariant);
if (false == regexCultivar.Match(this.Cultivar).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Cultivar, must match a pattern of " + regexCultivar, new [] { "Cultivar" });
}

// Origin (string) pattern
Regex regexOrigin = new Regex(@"^[A-Z\\s]*$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
Regex regexOrigin = new Regex("^[A-Z\\s]*$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
if (false == regexOrigin.Match(this.Origin).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Origin, must match a pattern of " + regexOrigin, new [] { "Origin" });
Original file line number Diff line number Diff line change
@@ -303,21 +303,21 @@ public override string ToString()
}

// PatternWithDigits (string) pattern
Regex regexPatternWithDigits = new Regex(@"^\\d{10}$", RegexOptions.CultureInvariant);
Regex regexPatternWithDigits = new Regex("^\\d{10}$", RegexOptions.CultureInvariant);
if (false == regexPatternWithDigits.Match(this.PatternWithDigits).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for PatternWithDigits, must match a pattern of " + regexPatternWithDigits, new [] { "PatternWithDigits" });
}

// PatternWithDigitsAndDelimiter (string) pattern
Regex regexPatternWithDigitsAndDelimiter = new Regex(@"^image_\\d{1,3}$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
Regex regexPatternWithDigitsAndDelimiter = new Regex("^image_\\d{1,3}$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
if (false == regexPatternWithDigitsAndDelimiter.Match(this.PatternWithDigitsAndDelimiter).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for PatternWithDigitsAndDelimiter, must match a pattern of " + regexPatternWithDigitsAndDelimiter, new [] { "PatternWithDigitsAndDelimiter" });
}

// StringProperty (string) pattern
Regex regexStringProperty = new Regex(@"[a-z]", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
Regex regexStringProperty = new Regex("[a-z]", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
if (false == regexStringProperty.Match(this.StringProperty).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for StringProperty, must match a pattern of " + regexStringProperty, new [] { "StringProperty" });
Original file line number Diff line number Diff line change
@@ -100,7 +100,7 @@ public override string ToString()
public IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> Validate(ValidationContext validationContext)
{
// UuidWithPattern (Guid) pattern
Regex regexUuidWithPattern = new Regex(@"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", RegexOptions.CultureInvariant);
Regex regexUuidWithPattern = new Regex("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", RegexOptions.CultureInvariant);
if (false == regexUuidWithPattern.Match(this.UuidWithPattern.ToString()).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for UuidWithPattern, must match a pattern of " + regexUuidWithPattern, new [] { "UuidWithPattern" });
Original file line number Diff line number Diff line change
@@ -98,7 +98,7 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
/// <returns>Filename</returns>
public static string SanitizeFilename(string filename)
{
Match match = Regex.Match(filename, @".*[/\\](.*)$");
Match match = Regex.Match(filename, ".*[/\\](.*)$");
return match.Success ? match.Groups[1].Value : filename;
}

Original file line number Diff line number Diff line change
@@ -80,14 +80,14 @@ public override string ToString()
public IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> Validate(ValidationContext validationContext)
{
// Cultivar (string) pattern
Regex regexCultivar = new Regex(@"^[a-zA-Z\\s]*$", RegexOptions.CultureInvariant);
Regex regexCultivar = new Regex("^[a-zA-Z\\s]*$", RegexOptions.CultureInvariant);
if (false == regexCultivar.Match(this.Cultivar).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Cultivar, must match a pattern of " + regexCultivar, new [] { "Cultivar" });
}

// Origin (string) pattern
Regex regexOrigin = new Regex(@"^[A-Z\\s]*$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
Regex regexOrigin = new Regex("^[A-Z\\s]*$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
if (false == regexOrigin.Match(this.Origin).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Origin, must match a pattern of " + regexOrigin, new [] { "Origin" });
Original file line number Diff line number Diff line change
@@ -301,21 +301,21 @@ public override string ToString()
}

// PatternWithDigits (string) pattern
Regex regexPatternWithDigits = new Regex(@"^\\d{10}$", RegexOptions.CultureInvariant);
Regex regexPatternWithDigits = new Regex("^\\d{10}$", RegexOptions.CultureInvariant);
if (false == regexPatternWithDigits.Match(this.PatternWithDigits).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for PatternWithDigits, must match a pattern of " + regexPatternWithDigits, new [] { "PatternWithDigits" });
}

// PatternWithDigitsAndDelimiter (string) pattern
Regex regexPatternWithDigitsAndDelimiter = new Regex(@"^image_\\d{1,3}$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
Regex regexPatternWithDigitsAndDelimiter = new Regex("^image_\\d{1,3}$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
if (false == regexPatternWithDigitsAndDelimiter.Match(this.PatternWithDigitsAndDelimiter).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for PatternWithDigitsAndDelimiter, must match a pattern of " + regexPatternWithDigitsAndDelimiter, new [] { "PatternWithDigitsAndDelimiter" });
}

// StringProperty (string) pattern
Regex regexStringProperty = new Regex(@"[a-z]", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
Regex regexStringProperty = new Regex("[a-z]", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
if (false == regexStringProperty.Match(this.StringProperty).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for StringProperty, must match a pattern of " + regexStringProperty, new [] { "StringProperty" });
Original file line number Diff line number Diff line change
@@ -98,7 +98,7 @@ public override string ToString()
public IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> Validate(ValidationContext validationContext)
{
// UuidWithPattern (Guid) pattern
Regex regexUuidWithPattern = new Regex(@"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", RegexOptions.CultureInvariant);
Regex regexUuidWithPattern = new Regex("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", RegexOptions.CultureInvariant);
if (false == regexUuidWithPattern.Match(this.UuidWithPattern.ToString()).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for UuidWithPattern, must match a pattern of " + regexUuidWithPattern, new [] { "UuidWithPattern" });
Original file line number Diff line number Diff line change
@@ -100,7 +100,7 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
/// <returns>Filename</returns>
public static string SanitizeFilename(string filename)
{
Match match = Regex.Match(filename, @".*[/\\](.*)$");
Match match = Regex.Match(filename, ".*[/\\](.*)$");
return match.Success ? match.Groups[1].Value : filename;
}

Original file line number Diff line number Diff line change
@@ -100,7 +100,7 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
/// <returns>Filename</returns>
public static string SanitizeFilename(string filename)
{
Match match = Regex.Match(filename, @".*[/\\](.*)$");
Match match = Regex.Match(filename, ".*[/\\](.*)$");
return match.Success ? match.Groups[1].Value : filename;
}

Original file line number Diff line number Diff line change
@@ -100,7 +100,7 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
/// <returns>Filename</returns>
public static string SanitizeFilename(string filename)
{
Match match = Regex.Match(filename, @".*[/\\](.*)$");
Match match = Regex.Match(filename, ".*[/\\](.*)$");
return match.Success ? match.Groups[1].Value : filename;
}

Original file line number Diff line number Diff line change
@@ -98,7 +98,7 @@ public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOp
/// <returns>Filename</returns>
public static string SanitizeFilename(string filename)
{
Match match = Regex.Match(filename, @".*[/\\](.*)$");
Match match = Regex.Match(filename, ".*[/\\](.*)$");
return match.Success ? match.Groups[1].Value : filename;
}

Original file line number Diff line number Diff line change
@@ -80,14 +80,14 @@ public override string ToString()
public IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> Validate(ValidationContext validationContext)
{
// Cultivar (string) pattern
Regex regexCultivar = new Regex(@"^[a-zA-Z\\s]*$", RegexOptions.CultureInvariant);
Regex regexCultivar = new Regex("^[a-zA-Z\\s]*$", RegexOptions.CultureInvariant);
if (false == regexCultivar.Match(this.Cultivar).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Cultivar, must match a pattern of " + regexCultivar, new [] { "Cultivar" });
}

// Origin (string) pattern
Regex regexOrigin = new Regex(@"^[A-Z\\s]*$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
Regex regexOrigin = new Regex("^[A-Z\\s]*$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
if (false == regexOrigin.Match(this.Origin).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Origin, must match a pattern of " + regexOrigin, new [] { "Origin" });
Original file line number Diff line number Diff line change
@@ -301,21 +301,21 @@ public override string ToString()
}

// PatternWithDigits (string) pattern
Regex regexPatternWithDigits = new Regex(@"^\\d{10}$", RegexOptions.CultureInvariant);
Regex regexPatternWithDigits = new Regex("^\\d{10}$", RegexOptions.CultureInvariant);
if (false == regexPatternWithDigits.Match(this.PatternWithDigits).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for PatternWithDigits, must match a pattern of " + regexPatternWithDigits, new [] { "PatternWithDigits" });
}

// PatternWithDigitsAndDelimiter (string) pattern
Regex regexPatternWithDigitsAndDelimiter = new Regex(@"^image_\\d{1,3}$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
Regex regexPatternWithDigitsAndDelimiter = new Regex("^image_\\d{1,3}$", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
if (false == regexPatternWithDigitsAndDelimiter.Match(this.PatternWithDigitsAndDelimiter).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for PatternWithDigitsAndDelimiter, must match a pattern of " + regexPatternWithDigitsAndDelimiter, new [] { "PatternWithDigitsAndDelimiter" });
}

// StringProperty (string) pattern
Regex regexStringProperty = new Regex(@"[a-z]", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
Regex regexStringProperty = new Regex("[a-z]", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
if (false == regexStringProperty.Match(this.StringProperty).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for StringProperty, must match a pattern of " + regexStringProperty, new [] { "StringProperty" });
Loading