| ... | @@ -13,7 +13,9 @@ module Gitlab |
... | @@ -13,7 +13,9 @@ module Gitlab |
|
|
super(logger: Gitlab::AppLogger)
|
|
super(logger: Gitlab::AppLogger)
|
|
|
|
|
|
|
|
@context = context
|
|
@context = context
|
|
|
@repository = context[:project].try(:repository)
|
|
@repository = context[:repository] || context[:project].try(:repository)
|
|
|
|
@max_includes = context[:max_includes].to_i
|
|
|
|
@included = []
|
|
|
|
|
|
|
|
# Note: Asciidoctor calls #freeze on extensions, so we can't set new
|
|
# Note: Asciidoctor calls #freeze on extensions, so we can't set new
|
|
|
# instance variables after initialization.
|
|
# instance variables after initialization.
|
| ... | @@ -28,8 +30,11 @@ module Gitlab |
... | @@ -28,8 +30,11 @@ module Gitlab |
|
|
def include_allowed?(target, reader)
|
|
def include_allowed?(target, reader)
|
|
|
doc = reader.document
|
|
doc = reader.document
|
|
|
|
|
|
|
|
return false if doc.attributes.fetch('max-include-depth').to_i < 1
|
|
max_include_depth = doc.attributes.fetch('max-include-depth').to_i
|
|
|
|
|
|
|
|
return false if max_include_depth < 1
|
|
|
return false if target_uri?(target)
|
|
return false if target_uri?(target)
|
|
|
|
return false if included.size >= max_includes
|
|
|
|
|
|
|
|
true
|
|
true
|
|
|
end
|
|
end
|
| ... | @@ -62,7 +67,7 @@ module Gitlab |
... | @@ -62,7 +67,7 @@ module Gitlab |
|
|
|
|
|
|
|
private
|
|
private
|
|
|
|
|
|
|
|
attr_accessor :context, :repository, :cache
|
|
attr_reader :context, :repository, :cache, :max_includes, :included
|
|
|
|
|
|
|
|
# Gets a Blob at a path for a specific revision.
|
|
# Gets a Blob at a path for a specific revision.
|
|
|
# This method will check that the Blob exists and contains readable text.
|
|
# This method will check that the Blob exists and contains readable text.
|
| ... | @@ -77,6 +82,8 @@ module Gitlab |
... | @@ -77,6 +82,8 @@ module Gitlab |
|
|
raise 'Blob not found' unless blob
|
|
raise 'Blob not found' unless blob
|
|
|
raise 'File is not readable' unless blob.readable_text?
|
|
raise 'File is not readable' unless blob.readable_text?
|
|
|
|
|
|
|
|
|
included << filename
|
|
|
|
|
|
|
blob
|
|
blob
|
|
|
end
|
|
end
|
|
|
|
|
|
| ... | |
... | |
| ... | | ... | |