lib/nanoc/data_sources/filesystem.rb in nanoc-4.12.6 vs lib/nanoc/data_sources/filesystem.rb in nanoc-4.12.7
- old
+ new
@@ -46,10 +46,12 @@
# understood by Ruby’s `Encoding`. If no encoding is set in the configuration,
# one will be inferred from the environment.
#
# @api private
class Filesystem < Nanoc::DataSource
+ PERMITTED_YAML_CLASSES = Nanoc::Core::ConfigLoader::PERMITTED_YAML_CLASSES
+
class AmbiguousMetadataAssociationError < ::Nanoc::Core::Error
def initialize(content_filenames, meta_filename)
super("There are multiple content files (#{content_filenames.sort.join(', ')}) that could match the file containing metadata (#{meta_filename}).")
end
end
@@ -114,11 +116,11 @@
attr_reader :content_checksum_data
attr_reader :attributes_checksum_data
attr_reader :is_binary
alias binary? is_binary
- def initialize(is_binary:, content: nil, filename: nil, attributes:, content_checksum_data: nil, attributes_checksum_data: nil)
+ def initialize(is_binary:, attributes:, content: nil, filename: nil, content_checksum_data: nil, attributes_checksum_data: nil)
if content.nil? && filename.nil?
raise ArgumentError, '#initialize needs at least content or filename'
end
@is_binary = is_binary
@@ -148,11 +150,11 @@
def read_proto_document(content_filename, meta_filename, klass)
is_binary = content_filename && !@site_config[:text_extensions].include?(File.extname(content_filename)[1..-1])
if is_binary && klass == Nanoc::Core::Item
- meta = (meta_filename && YAML.load_file(meta_filename, permitted_classes: Parser::PERMITTED_YAML_CLASSES)) || {}
+ meta = (meta_filename && YAML.safe_load_file(meta_filename, permitted_classes: PERMITTED_YAML_CLASSES)) || {}
ProtoDocument.new(is_binary: true, filename: content_filename, attributes: meta)
elsif is_binary && klass == Nanoc::Core::Layout
raise Errors::BinaryLayout.new(content_filename)
else
@@ -316,13 +318,11 @@
# Check number of files per type
unless [0, 1].include?(meta_filenames.size)
raise Errors::MultipleMetaFiles.new(meta_filenames, basename)
end
- unless config[:identifier_type] == 'full'
- unless [0, 1].include?(content_filenames.size)
- raise Errors::MultipleContentFiles.new(meta_filenames, basename)
- end
+ if (config[:identifier_type] != 'full') && ![0, 1].include?(content_filenames.size)
+ raise Errors::MultipleContentFiles.new(meta_filenames, basename)
end
all[basename] = []
all[basename][0] =
meta_filenames[0] ? 'yaml' : nil