Commit b6f5afb1 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'banzai-handle-removed-references' into 'master'

Banzai handle removed references

See merge request gitlab-org/gitlab!45426
parents 78d2375d e7a98807
......@@ -2,6 +2,8 @@
module Banzai
module ReferenceParser
InvalidReferenceType = Class.new(StandardError)
# Returns the reference parser class for the given type
#
# Example:
......@@ -11,6 +13,8 @@ module Banzai
# This would return the `Banzai::ReferenceParser::IssueParser` class.
def self.[](name)
const_get("#{name.to_s.camelize}Parser", false)
rescue NameError
raise InvalidReferenceType
end
end
end
......@@ -111,6 +111,7 @@ module Banzai
parser = Banzai::ReferenceParser[type].new(context)
visible.merge(parser.nodes_visible_to_user(user, nodes))
rescue Banzai::ReferenceParser::InvalidReferenceType
end
visible
......
......@@ -3,7 +3,7 @@
module Gitlab
module MarkdownCache
# Increment this number every time the renderer changes its output
CACHE_COMMONMARK_VERSION = 25
CACHE_COMMONMARK_VERSION = 26
CACHE_COMMONMARK_VERSION_START = 10
BaseError = Class.new(StandardError)
......
......@@ -182,5 +182,12 @@ RSpec.describe Banzai::ReferenceRedactor do
expect(redactor.nodes_visible_to_user([node])).to eq(Set.new([node]))
end
it 'handles invalid references gracefully' do
doc = Nokogiri::HTML.fragment('<a data-reference-type="some_invalid_type"></a>')
node = doc.children[0]
expect(redactor.nodes_visible_to_user([node])).to be_empty
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