Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/nuget/System.Text.Json-9.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gstraccini[bot] authored Nov 19, 2024
2 parents 57e7c05 + 32e4eab commit 2db08d8
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"csharpier": {
"version": "0.29.2",
"version": "0.30.1",
"commands": [
"dotnet-csharpier"
]
Expand Down
17 changes: 8 additions & 9 deletions Src/CrispyWaffle/Cryptography/Security.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,12 @@ public static string Hash(string value, HashAlgorithmType type)
/// <summary>
/// The hash algorithms.
/// </summary>
private static readonly Dictionary<HashAlgorithmType, HashAlgorithm> _hashAlgorithms =
new()
{
{ HashAlgorithmType.Md5, MD5.Create() },
{ HashAlgorithmType.Sha1, SHA1.Create() },
{ HashAlgorithmType.Sha256, SHA256.Create() },
{ HashAlgorithmType.Sha384, SHA384.Create() },
{ HashAlgorithmType.Sha512, SHA512.Create() },
};
private static readonly Dictionary<HashAlgorithmType, HashAlgorithm> _hashAlgorithms = new()
{
{ HashAlgorithmType.Md5, MD5.Create() },
{ HashAlgorithmType.Sha1, SHA1.Create() },
{ HashAlgorithmType.Sha256, SHA256.Create() },
{ HashAlgorithmType.Sha384, SHA384.Create() },
{ HashAlgorithmType.Sha512, SHA512.Create() },
};
}
39 changes: 25 additions & 14 deletions Src/CrispyWaffle/Scheduler/CronSchedulerValidations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,49 @@ public static class CronSchedulerValidations
/// A regular expression that matches cron syntax with the division operator (e.g., "*/5").
/// This expression is used to match fields that represent intervals (e.g., every 5th minute).
/// </summary>
public static readonly Regex DividedRegex =
new(@"(\*/\d+)", RegexOptions.Compiled, TimeSpan.FromSeconds(5));
public static readonly Regex DividedRegex = new(
@"(\*/\d+)",
RegexOptions.Compiled,
TimeSpan.FromSeconds(5)
);

/// <summary>
/// A regular expression that matches cron syntax with a range and optional divisor (e.g., "1-5/2").
/// This expression is used to match fields with ranges (e.g., from 1 to 5) and optionally a step value (e.g., every second value).
/// </summary>
public static readonly Regex RangeRegex =
new(@"(\d+\-\d+)\/?(\d+)?", RegexOptions.Compiled, TimeSpan.FromSeconds(5));
public static readonly Regex RangeRegex = new(
@"(\d+\-\d+)\/?(\d+)?",
RegexOptions.Compiled,
TimeSpan.FromSeconds(5)
);

/// <summary>
/// A regular expression that matches the wildcard character (*) in cron expressions.
/// The wildcard is used to match all values in a field (e.g., every minute, every day of the month).
/// </summary>
public static readonly Regex WildRegex =
new(@"(\*)", RegexOptions.Compiled, TimeSpan.FromSeconds(5));
public static readonly Regex WildRegex = new(
@"(\*)",
RegexOptions.Compiled,
TimeSpan.FromSeconds(5)
);

/// <summary>
/// A regular expression that matches lists of values separated by commas (e.g., "1,5,10").
/// This expression is used to match fields that specify multiple discrete values.
/// </summary>
public static readonly Regex ListRegex =
new(@"(((\d+,)*\d+)+)", RegexOptions.Compiled, TimeSpan.FromSeconds(5));
public static readonly Regex ListRegex = new(
@"(((\d+,)*\d+)+)",
RegexOptions.Compiled,
TimeSpan.FromSeconds(5)
);

/// <summary>
/// A combined validation regular expression that can match any of the individual cron syntax features.
/// This includes division, ranges, wildcards, and lists, and is used to validate entire cron expressions.
/// </summary>
public static readonly Regex ValidationRegex =
new(
DividedRegex + "|" + RangeRegex + "|" + WildRegex + "|" + ListRegex,
RegexOptions.Compiled,
TimeSpan.FromSeconds(5)
);
public static readonly Regex ValidationRegex = new(
DividedRegex + "|" + RangeRegex + "|" + WildRegex + "|" + ListRegex,
RegexOptions.Compiled,
TimeSpan.FromSeconds(5)
);
}
84 changes: 39 additions & 45 deletions Src/CrispyWaffle/TemplateRendering/Engines/MustachePatterns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,29 @@ internal static class MustachePatterns
/// <remarks>
/// This pattern captures the property being iterated over and the content inside the loop.
/// </remarks>
public static readonly Regex LoopPattern =
new(
@"{{\#each (?<property>.+?)}}(?<innerContent>.+?){{/each}}",
RegexOptions.Compiled
| RegexOptions.CultureInvariant
| RegexOptions.IgnoreCase
| RegexOptions.Singleline,
TimeSpan.FromSeconds(5)
);
public static readonly Regex LoopPattern = new(
@"{{\#each (?<property>.+?)}}(?<innerContent>.+?){{/each}}",
RegexOptions.Compiled
| RegexOptions.CultureInvariant
| RegexOptions.IgnoreCase
| RegexOptions.Singleline,
TimeSpan.FromSeconds(5)
);

/// <summary>
/// A regular expression pattern that matches a "with" construct (e.g., {{#with property}}...{{/with}}) in a Mustache template.
/// </summary>
/// <remarks>
/// This pattern captures the property being used and the content inside the "with" block.
/// </remarks>
public static readonly Regex WithPattern =
new(
@"{{\#with (?<property>.+?)}}(?<innerContent>.+?){{/with}}",
RegexOptions.Compiled
| RegexOptions.CultureInvariant
| RegexOptions.IgnoreCase
| RegexOptions.Singleline,
TimeSpan.FromSeconds(5)
);
public static readonly Regex WithPattern = new(
@"{{\#with (?<property>.+?)}}(?<innerContent>.+?){{/with}}",
RegexOptions.Compiled
| RegexOptions.CultureInvariant
| RegexOptions.IgnoreCase
| RegexOptions.Singleline,
TimeSpan.FromSeconds(5)
);

/// <summary>
/// A regular expression pattern that matches a conditional block (e.g., {{#condition}}...{{/condition}}) in a Mustache template.
Expand All @@ -48,28 +46,26 @@ internal static class MustachePatterns
/// <remarks>
/// This pattern captures the condition being evaluated, the content for the "true" case, and optionally, the content for the "else" case.
/// </remarks>
public static readonly Regex ConditionalPattern =
new(
@"{{\#(?<condition>.+?)}}(?<innerContent>.+?)(?:{{\#else}}(?<elseInnerContent>.+?))?{{/\1}}",
RegexOptions.Compiled
| RegexOptions.CultureInvariant
| RegexOptions.IgnoreCase
| RegexOptions.Singleline,
TimeSpan.FromSeconds(5)
);
public static readonly Regex ConditionalPattern = new(
@"{{\#(?<condition>.+?)}}(?<innerContent>.+?)(?:{{\#else}}(?<elseInnerContent>.+?))?{{/\1}}",
RegexOptions.Compiled
| RegexOptions.CultureInvariant
| RegexOptions.IgnoreCase
| RegexOptions.Singleline,
TimeSpan.FromSeconds(5)
);

/// <summary>
/// A regular expression pattern that matches a simple property reference (e.g., {{property}}) in a Mustache template.
/// </summary>
/// <remarks>
/// This pattern captures the name of the property to be replaced in the template.
/// </remarks>
public static readonly Regex PropertyPattern =
new(
"{{(?<property>.+?)}}",
RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase,
TimeSpan.FromSeconds(5)
);
public static readonly Regex PropertyPattern = new(
"{{(?<property>.+?)}}",
RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase,
TimeSpan.FromSeconds(5)
);

/// <summary>
/// A regular expression pattern that matches the "this" reference (e.g., {{this}}) in a Mustache template.
Expand All @@ -78,23 +74,21 @@ internal static class MustachePatterns
/// <remarks>
/// This pattern is used specifically in loops to refer to the current item in context.
/// </remarks>
public static readonly Regex LoopPropertyPattern =
new(
"{{this}}",
RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase,
TimeSpan.FromSeconds(5)
);
public static readonly Regex LoopPropertyPattern = new(
"{{this}}",
RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase,
TimeSpan.FromSeconds(5)
);

/// <summary>
/// A regular expression pattern that matches an import statement (e.g., {{>import file="filename"}}) in a Mustache template.
/// </summary>
/// <remarks>
/// This pattern captures key-value pairs in the import statement, specifically looking for "file" or "type" attributes.
/// </remarks>
public static readonly Regex ImportPattern =
new(
"{{>import (?<kvp>(?<key>file|type)=\"(?<value>.+?)\"\\s?){2}}}",
RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase,
TimeSpan.FromSeconds(5)
);
public static readonly Regex ImportPattern = new(
"{{>import (?<kvp>(?<key>file|type)=\"(?<value>.+?)\"\\s?){2}}}",
RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase,
TimeSpan.FromSeconds(5)
);
}
77 changes: 35 additions & 42 deletions Src/CrispyWaffle/Validations/StringValidations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,70 +19,63 @@ public static class StringValidations
/// <summary>
/// The Portuguese preposition pattern.
/// </summary>
public static readonly Regex PortuguesePrepositionPattern =
new(
"^(da|de|do|das|dos|no|na|nos|nas|-|etapa)$",
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase,
TimeSpan.FromSeconds(5)
);
public static readonly Regex PortuguesePrepositionPattern = new(
"^(da|de|do|das|dos|no|na|nos|nas|-|etapa)$",
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase,
TimeSpan.FromSeconds(5)
);

/// <summary>
/// The parentheses pattern (matches any content inside parentheses).
/// </summary>
public static readonly Regex ParenthesesPattern =
new(
@"\((.+?)\)",
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase,
TimeSpan.FromSeconds(5)
);
public static readonly Regex ParenthesesPattern = new(
@"\((.+?)\)",
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase,
TimeSpan.FromSeconds(5)
);

/// <summary>
/// The non-alphanumeric pattern (matches characters that are not letters, digits, or .@-).
/// </summary>
public static readonly Regex NonAlphanumericPattern =
new(
@"[^\w\.@-]",
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase,
TimeSpan.FromSeconds(5)
);
public static readonly Regex NonAlphanumericPattern = new(
@"[^\w\.@-]",
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase,
TimeSpan.FromSeconds(5)
);

/// <summary>
/// The non-numeric pattern (matches any character that is not a digit).
/// </summary>
public static readonly Regex NonNumericPattern =
new(
"[^0-9]",
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase,
TimeSpan.FromSeconds(5)
);
public static readonly Regex NonNumericPattern = new(
"[^0-9]",
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase,
TimeSpan.FromSeconds(5)
);

/// <summary>
/// The spaces pattern (matches any space character).
/// </summary>
public static readonly Regex SpacesPattern =
new(
@"\s+",
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase,
TimeSpan.FromSeconds(5)
);
public static readonly Regex SpacesPattern = new(
@"\s+",
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase,
TimeSpan.FromSeconds(5)
);

/// <summary>
/// The multiple spaces pattern (matches sequences of two or more spaces or tabs).
/// </summary>
public static readonly Regex MultipleSpacesPattern =
new(
@"[\t|\s]{2,}",
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase,
TimeSpan.FromSeconds(5)
);
public static readonly Regex MultipleSpacesPattern = new(
@"[\t|\s]{2,}",
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase,
TimeSpan.FromSeconds(5)
);

/// <summary>
/// The invalid file name pattern (matches invalid file name characters).
/// </summary>
public static readonly Regex InvalidFileName =
new(
$@"([{_invalidPathChars}]*\.+$)|([{_invalidPathChars}]+)",
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase,
TimeSpan.FromSeconds(5)
);
public static readonly Regex InvalidFileName = new(
$@"([{_invalidPathChars}]*\.+$)|([{_invalidPathChars}]+)",
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase,
TimeSpan.FromSeconds(5)
);
}

0 comments on commit 2db08d8

Please sign in to comment.