Commit 7bb52a0e authored by Igor Drozdov's avatar Igor Drozdov

Merge branch '204808_limit_anchor_href_length' into 'master'

Limit the length of generated anchor URL for markdown headers

See merge request gitlab-org/gitlab!78672
parents c96aef65 32b27239
......@@ -32,7 +32,7 @@ module Banzai
doc.xpath(XPATH).each do |node|
if header_content = node.children.first
id = string_to_anchor(node.text)
id = string_to_anchor(node.text[0...255])
uniq = headers[id] > 0 ? "-#{headers[id]}" : ''
headers[id] += 1
......
......@@ -91,6 +91,12 @@ RSpec.describe Banzai::Filter::TableOfContentsFilter do
# ExternalLinkFilter (see https://gitlab.com/gitlab-org/gitlab/issues/26210)
expect(doc.css('h1 a').first.attr('href')).to eq "##{CGI.escape('한글')}"
end
it 'limits header href length with 255 characters' do
doc = filter(header(1, 'a' * 500))
expect(doc.css('h1 a').first.attr('href')).to eq "##{'a' * 255}"
end
end
end
......
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