Skip to content

Commit

Permalink
Merge pull request #46 from NicolasConstant/develop
Browse files Browse the repository at this point in the history
0.6.1 PR
  • Loading branch information
NicolasConstant authored Jan 13, 2021
2 parents 59edb5b + 71954f3 commit ce5c843
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/BirdsiteLive.Domain/Tools/StatusExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public StatusExtractor(InstanceSettings instanceSettings)
// Replace return lines
messageContent = Regex.Replace(messageContent, @"\r\n\r\n?|\n\n", "</p><p> ");
messageContent = Regex.Replace(messageContent, @"\r\n?|\n", "<br/> ");
messageContent = Regex.Replace(messageContent, @"\(@", "( @");
messageContent = Regex.Replace(messageContent, @"\(#", "( #");

// Secure emojis
var emojiMatch = _emojiRegex.Matches(messageContent);
Expand Down Expand Up @@ -83,7 +85,7 @@ public StatusExtractor(InstanceSettings instanceSettings)

// Extract Hashtags
var hashtagMatch = OrderByLength(_hastagRegex.Matches(messageContent));
foreach (Match m in hashtagMatch)
foreach (Match m in hashtagMatch.OrderByDescending(x => x.Length))
{
var tag = m.ToString().Replace("#", string.Empty).Replace("\n", string.Empty).Trim();
var url = $"https://{_instanceSettings.Domain}/tags/{tag}";
Expand All @@ -101,7 +103,7 @@ public StatusExtractor(InstanceSettings instanceSettings)

// Extract Mentions
var mentionMatch = OrderByLength(_mentionRegex.Matches(messageContent));
foreach (Match m in mentionMatch)
foreach (Match m in mentionMatch.OrderByDescending(x => x.Length))
{
var mention = m.ToString().Replace("@", string.Empty).Replace("\n", string.Empty).Trim();
var url = $"https://{_instanceSettings.Domain}/users/{mention}";
Expand Down
2 changes: 1 addition & 1 deletion src/BirdsiteLive/BirdsiteLive.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<UserSecretsId>d21486de-a812-47eb-a419-05682bb68856</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<Version>0.6.0</Version>
<Version>0.6.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
17 changes: 17 additions & 0 deletions src/Tests/BirdsiteLive.Domain.Tests/Tools/StatusExtractorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,5 +335,22 @@ public void Extract_Emoji_Test()
Assert.IsTrue(result.content.Contains(@"😎 😍 🤗 🤩 😘"));
#endregion
}

[TestMethod]
public void Extract_Parenthesis_Test()
{
#region Stubs
var message = $"bla (@mynickname test)";
//var message = $"tests@mynickname";
#endregion

var service = new StatusExtractor(_settings);
var result = service.ExtractTags(message);

#region Validations
Assert.AreEqual(1, result.tags.Length);
Assert.IsTrue(result.content.Equals(@"bla ( <span class=""h-card""><a href=""https://domain.name/@mynickname"" class=""u-url mention"">@<span>mynickname</span></a></span> test)"));
#endregion
}
}
}

0 comments on commit ce5c843

Please sign in to comment.