Skip to content

feat : Add StringSyntax for regex parameters #40589

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

Merged
merged 7 commits into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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)
{
}
Expand Down
7 changes: 4 additions & 3 deletions src/Middleware/Rewrite/src/RewriteOptionsExtensions.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -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;
Expand Down