Commit 507cbca3 authored by Yorick Peterse's avatar Yorick Peterse

Fix header link rendering when containing numbers

This fixes the problem where Markdown such as:

    ### 31st

Would get rendered as a link tag pointing to issue number 31 inside a
header tag.

See gitlab-org/gitlab-ce#14936 for more information.
parent 59466a47
...@@ -119,7 +119,7 @@ module Banzai ...@@ -119,7 +119,7 @@ module Banzai
elsif element_node?(node) elsif element_node?(node)
yield_valid_link(node) do |link, text| yield_valid_link(node) do |link, text|
if ref_pattern && link =~ /\A#{ref_pattern}/ if ref_pattern && link =~ /\A#{ref_pattern}\z/
replace_link_node_with_href(node, link) do replace_link_node_with_href(node, link) do
object_link_filter(link, ref_pattern, link_text: text) object_link_filter(link, ref_pattern, link_text: text)
end end
......
...@@ -95,6 +95,14 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do ...@@ -95,6 +95,14 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do
result = reference_pipeline_result("Fixed #{reference}") result = reference_pipeline_result("Fixed #{reference}")
expect(result[:references][:issue]).to eq [issue] expect(result[:references][:issue]).to eq [issue]
end end
it 'does not process links containing issue numbers followed by text' do
href = "#{reference}st"
doc = reference_filter("<a href='#{href}'></a>")
link = doc.css('a').first.attr('href')
expect(link).to eq(href)
end
end end
context 'cross-project reference' do context 'cross-project reference' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment