added regexes
This commit is contained in:
parent
0bd8e38f28
commit
b2be896e95
6 changed files with 30 additions and 11 deletions
9
src/BirdsiteLive.Common/Regexes/HashtagRegexes.cs
Normal file
9
src/BirdsiteLive.Common/Regexes/HashtagRegexes.cs
Normal 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|$|[.,;:!?/|-])");
|
||||
}
|
||||
}
|
9
src/BirdsiteLive.Common/Regexes/UrlRegexes.cs
Normal file
9
src/BirdsiteLive.Common/Regexes/UrlRegexes.cs
Normal 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\-\@?^=%&/~\+#])?)");
|
||||
}
|
||||
}
|
|
@ -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_]+$");
|
||||
}
|
||||
}
|
10
src/BirdsiteLive.Common/Regexes/UserRegexes.cs
Normal file
10
src/BirdsiteLive.Common/Regexes/UserRegexes.cs
Normal 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|$|[,;:!?/|-]|(. ))");
|
||||
}
|
||||
}
|
|
@ -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"];
|
||||
|
|
|
@ -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)
|
||||
|
|
Reference in a new issue