Commit 02aad721 authored by Douwe Maan's avatar Douwe Maan

Only yield valid references in ReferenceFilter.references_in

parent a2801ec4
---
title: Only yield valid references in ReferenceFilter.references_in
merge_request:
author:
...@@ -33,7 +33,12 @@ module Banzai ...@@ -33,7 +33,12 @@ module Banzai
# Returns a String replaced with the return of the block. # Returns a String replaced with the return of the block.
def self.references_in(text, pattern = object_class.reference_pattern) def self.references_in(text, pattern = object_class.reference_pattern)
text.gsub(pattern) do |match| text.gsub(pattern) do |match|
yield match, $~[object_sym].to_i, $~[:project], $~[:namespace], $~ symbol = $~[object_sym]
if object_class.reference_valid?(symbol)
yield match, symbol.to_i, $~[:project], $~[:namespace], $~
else
match
end
end end
end end
......
...@@ -311,7 +311,7 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do ...@@ -311,7 +311,7 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do
end end
end end
describe '#issues_per_Project' do describe '#issues_per_project' do
context 'using an internal issue tracker' do context 'using an internal issue tracker' do
it 'returns a Hash containing the issues per project' do it 'returns a Hash containing the issues per project' do
doc = Nokogiri::HTML.fragment('') doc = Nokogiri::HTML.fragment('')
...@@ -346,4 +346,26 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do ...@@ -346,4 +346,26 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do
end end
end end
end end
describe '.references_in' do
let(:merge_request) { create(:merge_request) }
it 'yields valid references' do
expect do |b|
described_class.references_in(issue.to_reference, &b)
end.to yield_with_args(issue.to_reference, issue.iid, nil, nil, MatchData)
end
it "doesn't yield invalid references" do
expect do |b|
described_class.references_in('#0', &b)
end.not_to yield_control
end
it "doesn't yield unsupported references" do
expect do |b|
described_class.references_in(merge_request.to_reference, &b)
end.not_to yield_control
end
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