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.
This commit is contained in:
Yorick Peterse 2016-04-06 14:24:30 +02:00
parent 59466a4780
commit 507cbca339
2 changed files with 9 additions and 1 deletions

View file

@ -119,7 +119,7 @@ module Banzai
elsif element_node?(node)
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
object_link_filter(link, ref_pattern, link_text: text)
end

View file

@ -95,6 +95,14 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do
result = reference_pipeline_result("Fixed #{reference}")
expect(result[:references][:issue]).to eq [issue]
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
context 'cross-project reference' do