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 @@ ...@@ -2,6 +2,8 @@
module Banzai module Banzai
module ReferenceParser module ReferenceParser
InvalidReferenceType = Class.new(StandardError)
# Returns the reference parser class for the given type # Returns the reference parser class for the given type
# #
# Example: # Example:
...@@ -11,6 +13,8 @@ module Banzai ...@@ -11,6 +13,8 @@ module Banzai
# This would return the `Banzai::ReferenceParser::IssueParser` class. # This would return the `Banzai::ReferenceParser::IssueParser` class.
def self.[](name) def self.[](name)
const_get("#{name.to_s.camelize}Parser", false) const_get("#{name.to_s.camelize}Parser", false)
rescue NameError
raise InvalidReferenceType
end end
end end
end end
...@@ -111,6 +111,7 @@ module Banzai ...@@ -111,6 +111,7 @@ module Banzai
parser = Banzai::ReferenceParser[type].new(context) parser = Banzai::ReferenceParser[type].new(context)
visible.merge(parser.nodes_visible_to_user(user, nodes)) visible.merge(parser.nodes_visible_to_user(user, nodes))
rescue Banzai::ReferenceParser::InvalidReferenceType
end end
visible visible
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Gitlab module Gitlab
module MarkdownCache module MarkdownCache
# Increment this number every time the renderer changes its output # Increment this number every time the renderer changes its output
CACHE_COMMONMARK_VERSION = 25 CACHE_COMMONMARK_VERSION = 26
CACHE_COMMONMARK_VERSION_START = 10 CACHE_COMMONMARK_VERSION_START = 10
BaseError = Class.new(StandardError) BaseError = Class.new(StandardError)
......
...@@ -182,5 +182,12 @@ RSpec.describe Banzai::ReferenceRedactor do ...@@ -182,5 +182,12 @@ RSpec.describe Banzai::ReferenceRedactor do
expect(redactor.nodes_visible_to_user([node])).to eq(Set.new([node])) expect(redactor.nodes_visible_to_user([node])).to eq(Set.new([node]))
end 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
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