Commit a2513b18 authored by Stan Hu's avatar Stan Hu

Merge branch...

Merge branch '348748-expanding-gfm-references-into-titles-with-the-character-produces-invalid-urls' into 'master'

Remove extraneous `+` from expanded GFM url references

See merge request gitlab-org/gitlab!78229
parents 0408d49e 4a9a163c
...@@ -21,6 +21,7 @@ RSpec.describe Banzai::Filter::References::EpicReferenceFilter do ...@@ -21,6 +21,7 @@ RSpec.describe Banzai::Filter::References::EpicReferenceFilter do
context 'internal reference' do context 'internal reference' do
let(:reference) { "&#{epic.iid}" } let(:reference) { "&#{epic.iid}" }
let(:epic_url) { urls.group_epic_url(group, epic) }
it 'links to a valid reference' do it 'links to a valid reference' do
expect(doc.css('a').first.attr('href')).to eq(urls.group_epic_url(group, epic)) expect(doc.css('a').first.attr('href')).to eq(urls.group_epic_url(group, epic))
...@@ -66,17 +67,19 @@ RSpec.describe Banzai::Filter::References::EpicReferenceFilter do ...@@ -66,17 +67,19 @@ RSpec.describe Banzai::Filter::References::EpicReferenceFilter do
end end
it 'includes a data-reference-format attribute' do it 'includes a data-reference-format attribute' do
link = doc("&#{epic.iid}+").css('a').first link = doc("#{reference}+").css('a').first
expect(link).to have_attribute('data-reference-format') expect(link).to have_attribute('data-reference-format')
expect(link.attr('data-reference-format')).to eq('+') expect(link.attr('data-reference-format')).to eq('+')
expect(link.attr('href')).to eq(epic_url)
end end
it 'includes a data-reference-format attribute for URL references' do it 'includes a data-reference-format attribute for URL references' do
link = doc("#{urls.group_epic_url(group, epic)}+").css('a').first link = doc("#{epic_url}+").css('a').first
expect(link).to have_attribute('data-reference-format') expect(link).to have_attribute('data-reference-format')
expect(link.attr('data-reference-format')).to eq('+') expect(link.attr('data-reference-format')).to eq('+')
expect(link.attr('href')).to eq(epic_url)
end end
it 'ignores invalid epic IIDs' do it 'ignores invalid epic IIDs' do
......
...@@ -216,6 +216,8 @@ module Banzai ...@@ -216,6 +216,8 @@ module Banzai
url_for_object_cached(object, parent) url_for_object_cached(object, parent)
end end
url.chomp!(matches[:format]) if matches.names.include?("format")
content = link_content || object_link_text(object, matches) content = link_content || object_link_text(object, matches)
link = %(<a href="#{url}" #{data} link = %(<a href="#{url}" #{data}
......
...@@ -122,6 +122,7 @@ RSpec.describe Banzai::Filter::References::IssueReferenceFilter do ...@@ -122,6 +122,7 @@ RSpec.describe Banzai::Filter::References::IssueReferenceFilter do
expect(link).to have_attribute('data-reference-format') expect(link).to have_attribute('data-reference-format')
expect(link.attr('data-reference-format')).to eq('+') expect(link.attr('data-reference-format')).to eq('+')
expect(link.attr('href')).to eq(issue_url)
end end
it 'includes a data-reference-format attribute for URL references' do it 'includes a data-reference-format attribute for URL references' do
...@@ -130,6 +131,7 @@ RSpec.describe Banzai::Filter::References::IssueReferenceFilter do ...@@ -130,6 +131,7 @@ RSpec.describe Banzai::Filter::References::IssueReferenceFilter do
expect(link).to have_attribute('data-reference-format') expect(link).to have_attribute('data-reference-format')
expect(link.attr('data-reference-format')).to eq('+') expect(link.attr('data-reference-format')).to eq('+')
expect(link.attr('href')).to eq(issue_url)
end end
it 'supports an :only_path context' do it 'supports an :only_path context' do
......
...@@ -51,6 +51,7 @@ RSpec.describe Banzai::Filter::References::MergeRequestReferenceFilter do ...@@ -51,6 +51,7 @@ RSpec.describe Banzai::Filter::References::MergeRequestReferenceFilter do
context 'internal reference' do context 'internal reference' do
let(:reference) { merge.to_reference } let(:reference) { merge.to_reference }
let(:merge_request_url) { urls.project_merge_request_url(project, merge) }
it 'links to a valid reference' do it 'links to a valid reference' do
doc = reference_filter("See #{reference}") doc = reference_filter("See #{reference}")
...@@ -115,14 +116,16 @@ RSpec.describe Banzai::Filter::References::MergeRequestReferenceFilter do ...@@ -115,14 +116,16 @@ RSpec.describe Banzai::Filter::References::MergeRequestReferenceFilter do
expect(link).to have_attribute('data-reference-format') expect(link).to have_attribute('data-reference-format')
expect(link.attr('data-reference-format')).to eq('+') expect(link.attr('data-reference-format')).to eq('+')
expect(link.attr('href')).to eq(merge_request_url)
end end
it 'includes a data-reference-format attribute for URL references' do it 'includes a data-reference-format attribute for URL references' do
doc = reference_filter("Merge #{urls.project_merge_request_url(project, merge)}+") doc = reference_filter("Merge #{merge_request_url}+")
link = doc.css('a').first link = doc.css('a').first
expect(link).to have_attribute('data-reference-format') expect(link).to have_attribute('data-reference-format')
expect(link.attr('data-reference-format')).to eq('+') expect(link.attr('data-reference-format')).to eq('+')
expect(link.attr('href')).to eq(merge_request_url)
end end
it 'supports an :only_path context' do it 'supports an :only_path context' 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