diff --git a/lib/gitlab/markdown/label_reference_filter.rb b/lib/gitlab/markdown/label_reference_filter.rb index a357f28458d..1a77becee89 100644 --- a/lib/gitlab/markdown/label_reference_filter.rb +++ b/lib/gitlab/markdown/label_reference_filter.rb @@ -84,11 +84,11 @@ module Gitlab # # Returns a Hash. def label_params(id, name) - if id > 0 - { id: id } - else + if name # TODO (rspeicher): Don't strip single quotes if we decide to only use double quotes for surrounding. { name: name.tr('\'"', '') } + else + { id: id } end end end diff --git a/spec/lib/gitlab/markdown/label_reference_filter_spec.rb b/spec/lib/gitlab/markdown/label_reference_filter_spec.rb index 9f898837466..c4548e7431f 100644 --- a/spec/lib/gitlab/markdown/label_reference_filter_spec.rb +++ b/spec/lib/gitlab/markdown/label_reference_filter_spec.rb @@ -149,5 +149,12 @@ module Gitlab::Markdown end end end + + describe 'edge cases' do + it 'gracefully handles non-references matching the pattern' do + exp = act = '(format nil "~0f" 3.0) ; 3.0' + expect(filter(act).to_html).to eq exp + end + end end end