Skip to content
Snippets Groups Projects
Commit d31ea8ff authored by fauno's avatar fauno
Browse files

don't leak non core ruby objects to pandoc

parent 9a9e0939
No related branches found
No related tags found
No related merge requests found
...@@ -25,6 +25,10 @@ module Jekyll ...@@ -25,6 +25,10 @@ module Jekyll
class PandocFile class PandocFile
include Convertible include Convertible
ALLOWED_YAML_CLASSES = [Array, String, TrueClass, FalseClass,
NilClass, Hash, Integer, Float, Date,
Time, DateTime].freeze
attr_reader :format, :site, :config, :flags, :posts, :slug, :title, :url attr_reader :format, :site, :config, :flags, :posts, :slug, :title, :url
attr_reader :papersize, :sheetsize, :signature, :sources attr_reader :papersize, :sheetsize, :signature, :sources
...@@ -117,10 +121,18 @@ module Jekyll ...@@ -117,10 +121,18 @@ module Jekyll
data = Jekyll::Utils.deep_merge_hashes @config, single_post.data data = Jekyll::Utils.deep_merge_hashes @config, single_post.data
single_post.merge_data! data single_post.merge_data! data
# if we dump to YAML any other value pandoc tends to use lots
# we extract the excerpt because it serializes as an object and # and lots of RAM
# breaks pandoc metadata = single_post.data.select do |_, v|
metadata = single_post.data.reject{ |k| k == 'excerpt' } case v
when Array
v.all? { |x| ALLOWED_YAML_CLASSES.include? x.class }
when Hash
v.values.all? { |x| ALLOWED_YAML_CLASSES.include? x.class }
else
ALLOWED_YAML_CLASSES.include? v.class
end
end
if @config['date_format'] if @config['date_format']
metadata['date'] = metadata['date'].strftime(@config['date_format']) metadata['date'] = metadata['date'].strftime(@config['date_format'])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment