diff --git a/app/helpers/markup_helper.rb b/app/helpers/markup_helper.rb
index e2524938e10f161d3023ba653b3cf65c81c7d018..e1e756c2f4ce6c79a22c328bb850dd02287a485c 100644
--- a/app/helpers/markup_helper.rb
+++ b/app/helpers/markup_helper.rb
@@ -51,12 +51,15 @@ def link_to_html(redacted, url, html_options = {})
text = fragment.children[0].text
fragment.children[0].replace(link_to(text, url, html_options))
else
- # Traverse the fragment's first generation of children looking for pure
- # text, wrapping anything found in the requested link
+ # Traverse the fragment's first generation of children looking for
+ # either pure text or emojis, wrapping anything found in the
+ # requested link
fragment.children.each do |node|
- next unless node.text?
-
- node.replace(link_to(node.text, url, html_options))
+ if node.text?
+ node.replace(link_to(node.text, url, html_options))
+ elsif node.name == 'gl-emoji'
+ node.replace(link_to(node.to_html.html_safe, url, html_options))
+ end
end
end
diff --git a/changelogs/unreleased/harishsr-emoticon-commit-links.yml b/changelogs/unreleased/harishsr-emoticon-commit-links.yml
new file mode 100644
index 0000000000000000000000000000000000000000..0ad9dd1e101e48a2241a23885c9d0489166406c0
--- /dev/null
+++ b/changelogs/unreleased/harishsr-emoticon-commit-links.yml
@@ -0,0 +1,5 @@
+---
+title: Allow emojis to be linkable
+merge_request: 18014
+author:
+type: fixed
diff --git a/spec/helpers/markup_helper_spec.rb b/spec/helpers/markup_helper_spec.rb
index 32851249b2e25e488f0278e9825d8daece6e98e2..683c04428abdc0b27d2803d559b5bd2d27b81794 100644
--- a/spec/helpers/markup_helper_spec.rb
+++ b/spec/helpers/markup_helper_spec.rb
@@ -210,7 +210,7 @@
it 'replaces commit message with emoji to link' do
actual = link_to_markdown(':book: Book', '/foo')
expect(actual)
- .to eq '📖 Book'
+ .to eq '📖 Book'
end
end
@@ -232,6 +232,12 @@
expect(doc.css('a')[0].attr('href')).to eq link
expect(doc.css('a')[0].text).to eq 'This should finally fix '
end
+
+ it "escapes HTML passed as an emoji" do
+ rendered = '<div class="test">test</div>'
+ expect(helper.link_to_html(rendered, '/foo'))
+ .to eq '<div class="test">test</div>'
+ end
end
describe '#render_wiki_content' do