lib/liquid/template.rb in liquid-5.4.0 vs lib/liquid/template.rb in liquid-5.5.0
- old
+ new
@@ -13,11 +13,11 @@
#
# template = Liquid::Template.parse(source)
# template.render('user_name' => 'bob')
#
class Template
- attr_accessor :root
+ attr_accessor :root, :name
attr_reader :resource_limits, :warnings
class TagRegistry
include Enumerable
@@ -105,10 +105,16 @@
# Parse source code.
# Returns self for easy chaining
def parse(source, options = {})
parse_context = configure_options(options)
+ source = source.to_s.to_str
+
+ unless source.valid_encoding?
+ raise TemplateEncodingError, parse_context.locale.t("errors.syntax.invalid_template_encoding")
+ end
+
tokenizer = parse_context.new_tokenizer(source, start_line_number: @line_numbers && 1)
@root = Document.parse(tokenizer, parse_context)
self
end
@@ -186,9 +192,11 @@
context.resource_limits.reset
if @profiling && context.profiler.nil?
@profiler = context.profiler = Liquid::Profiler.new
end
+
+ context.template_name ||= name
begin
# render the nodelist.
@root.render_to_output_buffer(context, output || +'')
rescue Liquid::MemoryError => e