-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UrlFormatChecker for Centeralize Regex
- Loading branch information
1 parent
e40b84a
commit fd6f10a
Showing
6 changed files
with
43 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 4 additions & 6 deletions
10
src/SwiftLink.Presentation/Filters/ShortenEndpointFilter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
using SwiftLink.Application.UseCases.Links.GenerateCommand; | ||
using SwiftLink.Shared; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace SwiftLink.Presentation.Filters; | ||
|
||
public partial class ShortenEndpointFilter : ActionFilterAttribute | ||
{ | ||
private const int _urlArgumentIndex = 0; | ||
private const string _pattern = @"^(?:(?:https?|ftp)://)?[^\s/$.?#].[^\s]*$"; | ||
|
||
|
||
public override void OnActionExecuting(ActionExecutingContext context) | ||
{ | ||
} | ||
|
||
private static bool IsValidUrl(string url) | ||
=> ShortCodeRegex().IsMatch(url); | ||
|
||
[GeneratedRegex(_pattern, RegexOptions.IgnoreCase, "en-US")] | ||
private static partial Regex ShortCodeRegex(); | ||
=> UrlFormatChecker.UrlRegex().IsMatch(url); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Text.RegularExpressions; | ||
|
||
namespace SwiftLink.Shared; | ||
public static partial class UrlFormatChecker | ||
{ | ||
private const string _pattern = @"^(https?|ftp)://[^\s/$.?#].[^\s]*$"; | ||
|
||
[GeneratedRegex(_pattern, RegexOptions.IgnoreCase, "en-US")] | ||
public static partial Regex UrlRegex(); | ||
} |