Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: recursion on emojis renderer #2105

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Text.RegularExpressions;
using NUnit.Framework;
using pyRevitLabs.Emojis;

namespace pyRevitLabs.Emojis.Tests
{
public class Tests
{
[SetUp]
public void Setup()
{
}

[Test]
public void TestRepeatedEmojis()
{
var input = ":cross_mark: :cross_mark:";
var rendered = Emojis.Emojize(input);
var regex = new Regex("<span><img src=");
var matches = regex.Matches(rendered);
Assert.AreEqual(2, matches.Count);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../pyRevitLabs.Emojis/pyRevitLabs.Emojis.csproj" />
</ItemGroup>
</Project>
9 changes: 6 additions & 3 deletions dev/pyRevitLabs/pyRevitLabs.Emojis/Emojis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.IO;
using System.IO.Compression;
using System.Drawing;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Reflection;
Expand Down Expand Up @@ -2645,10 +2646,12 @@ public static string Emojize(string input) {
if (_emojiZip is null)
ExtractEmojis();

var matches = new Regex(@"\:(?<code>[^\s]+?)\:").Matches(input);
var matches = new Regex(@"\:(?<code>[^\s]+?)\:").Matches(input)
.Cast<Match>()
.Select(m => m.Groups["code"].Value)
.Distinct();
// find the emoji shorthands
foreach (Match match in matches) {
var emojiShortCode = match.Groups["code"].Value;
foreach (var emojiShortCode in matches) {
if (EmojiDict.ContainsKey(emojiShortCode)) {
// find the emoji unicode
var shortHand = string.Format(":{0}:", emojiShortCode);
Expand Down
Loading