Skip to content

Commit

Permalink
fine-tuning regex
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasConstant committed Feb 3, 2021
1 parent 717f690 commit 32b53e0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/BirdsiteLive.Common/Regexes/HashtagRegexes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace BirdsiteLive.Common.Regexes
public class HashtagRegexes
{
public static readonly Regex HashtagName = new Regex(@"^[a-zA-Z0-9_]+$");
public static readonly Regex Hashtag = new Regex(@"(.?)#([a-zA-Z0-9_]+)(\s|$|[<.,;:!?/|-])");
public static readonly Regex Hashtag = new Regex(@"(.?)#([a-zA-Z0-9_]+)(\s|$|[\[\]<>.,;:!?/|-])");
}
}
2 changes: 1 addition & 1 deletion src/BirdsiteLive.Common/Regexes/UserRegexes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ 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|$|[<,;:!?/|-]|(. ))");
public static readonly Regex Mention = new Regex(@"(.?)@([a-zA-Z0-9_]+)(\s|$|[\[\]<>,;:!?/|-]|(. ))");
}
}
26 changes: 26 additions & 0 deletions src/Tests/BirdsiteLive.Domain.Tests/Tools/StatusExtractorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,32 @@ public void Extract_SingleMentionTag_Test()
#endregion
}

[TestMethod]
public void Extract_SingleMentionTag_RT_Test()
{
#region Stubs
var message = $"[RT @mynickname]{Environment.NewLine}Bla!";
#endregion

#region Mocks
var logger = new Mock<ILogger<StatusExtractor>>();
#endregion

var service = new StatusExtractor(_settings, logger.Object);
var result = service.Extract(message);

#region Validations
logger.VerifyAll();
Assert.AreEqual(1, result.tags.Length);
Assert.AreEqual("@[email protected]", result.tags.First().name);
Assert.AreEqual("Mention", result.tags.First().type);
Assert.AreEqual("https://domain.name/users/mynickname", result.tags.First().href);

Assert.IsTrue(result.content.Contains("Bla!"));
Assert.IsTrue(result.content.Contains(@"<span class=""h-card""><a href=""https://domain.name/@mynickname"" class=""u-url mention"">@<span>mynickname</span></a></span>"));
#endregion
}

[TestMethod]
public void Extract_SingleMentionTag_Dot_Test()
{
Expand Down

0 comments on commit 32b53e0

Please sign in to comment.