added regexes

This commit is contained in:
Nicolas Constant 2021-02-01 20:19:14 -05:00
parent 0bd8e38f28
commit b2be896e95
No known key found for this signature in database
GPG key ID: 1E9F677FB01A5688
6 changed files with 30 additions and 11 deletions

View file

@ -0,0 +1,9 @@
using System.Text.RegularExpressions;
namespace BirdsiteLive.Common.Regexes
{
public class HashtagRegexes
{
public static readonly Regex Hashtag = new Regex(@"(.)(#[a-zA-Z0-9]+)(\s|$|[.,;:!?/|-])");
}
}

View file

@ -0,0 +1,9 @@
using System.Text.RegularExpressions;
namespace BirdsiteLive.Common.Regexes
{
public class UrlRegexes
{
public static readonly Regex Url = new Regex(@"((http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)");
}
}

View file

@ -1,9 +0,0 @@
using System.Text.RegularExpressions;
namespace BirdsiteLive.Common.Regexes
{
public class UserRegex
{
public static readonly Regex TwitterAccountRegex = new Regex(@"^[a-zA-Z0-9_]+$");
}
}

View file

@ -0,0 +1,10 @@
using System.Text.RegularExpressions;
namespace BirdsiteLive.Common.Regexes
{
public class UserRegexes
{
public static readonly Regex TwitterAccount = new Regex(@"^[a-zA-Z0-9_]+$");
public static readonly Regex Mention = new Regex(@"(.)(@[a-zA-Z0-9_]+)(\s|$|[,;:!?/|-]|(. ))");
}
}

View file

@ -62,7 +62,7 @@ namespace BirdsiteLive.Controllers
// Ensure valid username
// https://help.twitter.com/en/managing-your-account/twitter-username-rules
TwitterUser user = null;
if (!string.IsNullOrWhiteSpace(id) && UserRegex.TwitterAccountRegex.IsMatch(id) && id.Length <= 15)
if (!string.IsNullOrWhiteSpace(id) && UserRegexes.TwitterAccount.IsMatch(id) && id.Length <= 15)
user = _twitterUserService.GetUser(id);
var acceptHeaders = Request.Headers["Accept"];

View file

@ -164,7 +164,7 @@ namespace BirdsiteLive.Controllers
// Ensure valid username
// https://help.twitter.com/en/managing-your-account/twitter-username-rules
if (string.IsNullOrWhiteSpace(name) || !UserRegex.TwitterAccountRegex.IsMatch(name) || name.Length > 15 )
if (string.IsNullOrWhiteSpace(name) || !UserRegexes.TwitterAccount.IsMatch(name) || name.Length > 15 )
return NotFound();
if (!string.IsNullOrWhiteSpace(domain) && domain != _settings.Domain)