Commit 1fb49ccd authored by Sean McGivern's avatar Sean McGivern

Merge branch 'jprovazn-ignore-anchors' into 'master'

Use prefix for TableOfContents filter hrefs

Closes #38473

See merge request gitlab-org/gitlab-ce!15806
parents 103269b9 3e83d9f7
title: Fix false positive issue references in merge requests caused by header anchor
type: fixed
......@@ -32,6 +32,7 @@ def call
.gsub(PUNCTUATION_REGEXP, '') # remove punctuation
.tr(' ', '-') # replace spaces with dash
.squeeze('-') # replace multiple dashes with one
.gsub(/\A(\d+)\z/, 'anchor-\1') # digits-only hrefs conflict with issue refs
uniq = headers[id] > 0 ? "-#{headers[id]}" : ''
headers[id] += 1
......@@ -65,6 +65,13 @@ def header(level, text)
expect(doc.css('h2 a').first.attr('href')).to eq '#one-1'
it 'prepends a prefix to digits-only ids' do
doc = filter(header(1, "123") + header(2, "1.0"))
expect(doc.css('h1 a').first.attr('href')).to eq '#anchor-123'
expect(doc.css('h2 a').first.attr('href')).to eq '#anchor-10'
it 'supports Unicode' do
doc = filter(header(1, '한글'))
expect(doc.css('h1 a').first.attr('id')).to eq 'user-content-한글'
......@@ -115,6 +115,15 @@
it 'does not include anchors from table of contents in issue references' do
issue1 = create(:issue, project: project)
issue2 = create(:issue, project: project)
subject.analyze("not real issue <h4>#{issue1.iid}</h4>, real issue #{issue2.to_reference}")
expect(subject.issues).to match_array([issue2])
it 'accesses valid issue objects' do
@i0 = create(:issue, project: project)
@i1 = create(:issue, project: project)
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