summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/emoji/emoji.go19
-rw-r--r--modules/markup/html_test.go4
2 files changed, 22 insertions, 1 deletions
diff --git a/modules/emoji/emoji.go b/modules/emoji/emoji.go
index e2c3d202e2..169ee0a182 100644
--- a/modules/emoji/emoji.go
+++ b/modules/emoji/emoji.go
@@ -130,6 +130,8 @@ func ReplaceAliases(s string) string {
// FindEmojiSubmatchIndex returns index pair of longest emoji in a string
func FindEmojiSubmatchIndex(s string) []int {
loadMap()
+ found := make(map[int]int)
+ keys := make([]int, 0)
//see if there are any emoji in string before looking for position of specific ones
//no performance difference when there is a match but 10x faster when there are not
@@ -137,11 +139,26 @@ func FindEmojiSubmatchIndex(s string) []int {
return nil
}
+ // get index of first emoji occurrence while also checking for longest combination
for j := range GemojiData {
i := strings.Index(s, GemojiData[j].Emoji)
if i != -1 {
- return []int{i, i + len(GemojiData[j].Emoji)}
+ if _, ok := found[i]; !ok {
+ if len(keys) == 0 || i < keys[0] {
+ found[i] = j
+ keys = []int{i}
+ }
+ if i == 0 {
+ break
+ }
+ }
}
}
+
+ if len(keys) > 0 {
+ index := keys[0]
+ return []int{index, index + len(GemojiData[found[index]].Emoji)}
+ }
+
return nil
}
diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go
index a73236a7a3..69c4e675f5 100644
--- a/modules/markup/html_test.go
+++ b/modules/markup/html_test.go
@@ -266,6 +266,10 @@ func TestRender_emoji(t *testing.T) {
test(
"Some text with 😄😄 2 emoji next to each other",
`<p>Some text with <span class="emoji" aria-label="grinning face with smiling eyes">😄</span><span class="emoji" aria-label="grinning face with smiling eyes">😄</span> 2 emoji next to each other</p>`)
+ test(
+ "😎ðŸĪŠðŸ”ðŸĪ‘❓",
+ `<p><span class="emoji" aria-label="smiling face with sunglasses">😎</span><span class="emoji" aria-label="zany face">ðŸĪŠ</span><span class="emoji" aria-label="locked with key">🔐</span><span class="emoji" aria-label="money-mouth face">ðŸĪ‘</span><span class="emoji" aria-label="question mark">❓</span></p>`)
+
// should match nothing
test(
"2001:0db8:85a3:0000:0000:8a2e:0370:7334",