diff --git a/src/Http/Routing/src/Constraints/RegexInlineRouteConstraint.cs b/src/Http/Routing/src/Constraints/RegexInlineRouteConstraint.cs index 465e0a9f9c5d..50963a0df25f 100644 --- a/src/Http/Routing/src/Constraints/RegexInlineRouteConstraint.cs +++ b/src/Http/Routing/src/Constraints/RegexInlineRouteConstraint.cs @@ -1,6 +1,9 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics.CodeAnalysis; +using System.Text.RegularExpressions; + namespace Microsoft.AspNetCore.Routing.Constraints; /// <summary> @@ -12,7 +15,7 @@ public class RegexInlineRouteConstraint : RegexRouteConstraint /// Initializes a new instance of the <see cref="RegexInlineRouteConstraint" /> class. /// </summary> /// <param name="regexPattern">The regular expression pattern to match.</param> - public RegexInlineRouteConstraint(string regexPattern) + public RegexInlineRouteConstraint([StringSyntax(StringSyntaxAttribute.Regex, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase)] string regexPattern) : base(regexPattern) { } diff --git a/src/Middleware/Rewrite/src/RewriteOptionsExtensions.cs b/src/Middleware/Rewrite/src/RewriteOptionsExtensions.cs index 37baa577c20e..7a0841b1dd32 100644 --- a/src/Middleware/Rewrite/src/RewriteOptionsExtensions.cs +++ b/src/Middleware/Rewrite/src/RewriteOptionsExtensions.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics.CodeAnalysis; using Microsoft.AspNetCore.Http; namespace Microsoft.AspNetCore.Rewrite; @@ -42,7 +43,7 @@ public static RewriteOptions Add(this RewriteOptions options, Action<RewriteCont /// <param name="replacement">If the regex matches, what to replace the uri with.</param> /// <param name="skipRemainingRules">If the regex matches, conditionally stop processing other rules.</param> /// <returns>The Rewrite options.</returns> - public static RewriteOptions AddRewrite(this RewriteOptions options, string regex, string replacement, bool skipRemainingRules) + public static RewriteOptions AddRewrite(this RewriteOptions options, [StringSyntax(StringSyntaxAttribute.Regex)] string regex, string replacement, bool skipRemainingRules) { options.Rules.Add(new RewriteRule(regex, replacement, skipRemainingRules)); return options; @@ -55,7 +56,7 @@ public static RewriteOptions AddRewrite(this RewriteOptions options, string rege /// <param name="regex">The regex string to compare with.</param> /// <param name="replacement">If the regex matches, what to replace the uri with.</param> /// <returns>The Rewrite options.</returns> - public static RewriteOptions AddRedirect(this RewriteOptions options, string regex, string replacement) + public static RewriteOptions AddRedirect(this RewriteOptions options, [StringSyntax(StringSyntaxAttribute.Regex)] string regex, string replacement) { return AddRedirect(options, regex, replacement, statusCode: StatusCodes.Status302Found); } @@ -68,7 +69,7 @@ public static RewriteOptions AddRedirect(this RewriteOptions options, string reg /// <param name="replacement">If the regex matches, what to replace the uri with.</param> /// <param name="statusCode">The status code to add to the response.</param> /// <returns>The Rewrite options.</returns> - public static RewriteOptions AddRedirect(this RewriteOptions options, string regex, string replacement, int statusCode) + public static RewriteOptions AddRedirect(this RewriteOptions options, [StringSyntax(StringSyntaxAttribute.Regex)] string regex, string replacement, int statusCode) { options.Rules.Add(new RedirectRule(regex, replacement, statusCode)); return options;