Commit 32b27239 authored by Vasilii Iakliushin's avatar Vasilii Iakliushin

Limit the length of generated anchor URL for markdown headers

Contributes to https://gitlab.com/gitlab-org/gitlab/-/issues/204808

**Problem**

There is no limitation for generated header anchors. It might cause
performance problems for long headers processing.

**Solution**

Limit anchor link length with 255 characters.

Changelog: changed
parent d4aeaf21
......@@ -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