diff options
author | Robert Speicher <robert@gitlab.com> | 2017-04-16 16:15:50 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2017-04-16 16:15:50 +0000 |
commit | f78ecda55d5431f9a74ab2892b516ecb45f24d80 (patch) | |
tree | 5cdb2f2159e699b8bb0c72e209dfe934ee72c825 | |
parent | ae52d1a4b82cd86130c92795390fc3d9664d180b (diff) | |
parent | e89d4741d38bdbb645d5bf92cfdac5d66e8438b0 (diff) | |
download | gitlab-ce-f78ecda55d5431f9a74ab2892b516ecb45f24d80.tar.gz |
Merge branch 'sh-fix-base-parser' into 'master'
Fix regression in rendering Markdown references that do not exist
Closes #30972
See merge request !10716
-rw-r--r-- | lib/banzai/reference_parser/base_parser.rb | 3 | ||||
-rw-r--r-- | spec/lib/banzai/reference_parser/base_parser_spec.rb | 23 |
2 files changed, 23 insertions, 3 deletions
diff --git a/lib/banzai/reference_parser/base_parser.rb b/lib/banzai/reference_parser/base_parser.rb index dabf71d6aeb..c2503fa2adc 100644 --- a/lib/banzai/reference_parser/base_parser.rb +++ b/lib/banzai/reference_parser/base_parser.rb @@ -136,7 +136,8 @@ module Banzai nodes.each_with_object({}) do |node, hash| if node.has_attribute?(attribute) - hash[node] = objects_by_id[node.attr(attribute).to_i] + obj = objects_by_id[node.attr(attribute).to_i] + hash[node] = obj if obj end end end diff --git a/spec/lib/banzai/reference_parser/base_parser_spec.rb b/spec/lib/banzai/reference_parser/base_parser_spec.rb index a3141894c74..d5746107ee1 100644 --- a/spec/lib/banzai/reference_parser/base_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/base_parser_spec.rb @@ -114,8 +114,27 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do expect(hash).to eq({ link => user }) end - it 'returns an empty Hash when the list of nodes is empty' do - expect(subject.grouped_objects_for_nodes([], User, 'data-user')).to eq({}) + it 'returns an empty Hash when entry does not exist in the database' do + link = double(:link) + + expect(link).to receive(:has_attribute?). + with('data-user'). + and_return(true) + + expect(link).to receive(:attr). + with('data-user'). + and_return('1') + + nodes = [link] + bad_id = user.id + 100 + + expect(subject).to receive(:unique_attribute_values). + with(nodes, 'data-user'). + and_return([bad_id.to_s]) + + hash = subject.grouped_objects_for_nodes(nodes, User, 'data-user') + + expect(hash).to eq({}) end end |