From 5eff37509468203c316257f3d28f9421c6846656 Mon Sep 17 00:00:00 2001 From: Florian Weingarten Date: Thu, 14 Aug 2014 16:11:21 +0000 Subject: [PATCH 01/12] Optional line numbers for liquid errors --- lib/liquid.rb | 2 +- lib/liquid/block.rb | 2 +- lib/liquid/context.rb | 13 +++------ lib/liquid/errors.rb | 32 +++++++++++++++++++- lib/liquid/template.rb | 7 +++-- lib/liquid/{profiler => }/token.rb | 2 -- test/integration/error_handling_test.rb | 39 +++++++++++++++++++++++-- 7 files changed, 77 insertions(+), 20 deletions(-) rename lib/liquid/{profiler => }/token.rb (99%) diff --git a/lib/liquid.rb b/lib/liquid.rb index c1fac5f..cc56eb0 100644 --- a/lib/liquid.rb +++ b/lib/liquid.rb @@ -66,11 +66,11 @@ require 'liquid/standardfilters' require 'liquid/condition' require 'liquid/module_ex' require 'liquid/utils' +require 'liquid/token' # Load all the tags of the standard library # Dir[File.dirname(__FILE__) + '/liquid/tags/*.rb'].each { |f| require f } require 'liquid/profiler' -require 'liquid/profiler/token' require 'liquid/profiler/hooks' diff --git a/lib/liquid/block.rb b/lib/liquid/block.rb index 5503913..a53c282 100644 --- a/lib/liquid/block.rb +++ b/lib/liquid/block.rb @@ -144,7 +144,7 @@ module Liquid rescue MemoryError => e raise e rescue ::StandardError => e - output << (context.handle_error(e)) + output << (context.handle_error(e, token)) end end diff --git a/lib/liquid/context.rb b/lib/liquid/context.rb index 9ff7260..0df9f77 100644 --- a/lib/liquid/context.rb +++ b/lib/liquid/context.rb @@ -91,17 +91,12 @@ module Liquid @interrupts.pop end - def handle_error(e) + + def handle_error(e, token) + e = Liquid::Error.error_with_line_number(e, token) errors.push(e) - raise if exception_handler && exception_handler.call(e) - - case e - when SyntaxError - "Liquid syntax error: #{e.message}" - else - "Liquid error: #{e.message}" - end + Liquid::Error.render(e) end def invoke(method, *args) diff --git a/lib/liquid/errors.rb b/lib/liquid/errors.rb index 85cb373..da03886 100644 --- a/lib/liquid/errors.rb +++ b/lib/liquid/errors.rb @@ -1,5 +1,35 @@ module Liquid - class Error < ::StandardError; end + class Error < ::StandardError + attr_accessor :line_number + + def self.render(e) + msg = if e.is_a?(Liquid::Error) && e.line_number + "#{e.line_number}: #{e.message}" + else + e.message + end + + case e + when SyntaxError + "Liquid syntax error: #{msg}" + else + "Liquid error: #{msg}" + end + end + + def self.error_with_line_number(e, token) + if e.is_a?(Liquid::Error) + e.set_line_number_from_token(token) + end + + e + end + + def set_line_number_from_token(token) + return unless token.respond_to?(:line_number) + self.line_number = token.line_number + end + end class ArgumentError < Error; end class ContextError < Error; end diff --git a/lib/liquid/template.rb b/lib/liquid/template.rb index a1a6f55..8a496e1 100644 --- a/lib/liquid/template.rb +++ b/lib/liquid/template.rb @@ -105,6 +105,8 @@ module Liquid def parse(source, options = {}) @options = options @profiling = options[:profile] + @profiling = options.delete(:profile) + @line_numbers = options.delete(:line_numbers) || @profiling @root = Document.parse(tokenize(source), DEFAULT_OPTIONS.merge(options)) @warnings = nil self @@ -197,7 +199,7 @@ module Liquid end result.respond_to?(:join) ? result.join : result rescue Liquid::MemoryError => e - context.handle_error(e) + context.handle_error(e, nil) ensure @errors = context.errors end @@ -224,7 +226,7 @@ module Liquid end def calculate_line_numbers(raw_tokens) - return raw_tokens unless @profiling + return raw_tokens unless @line_numbers current_line = 1 raw_tokens.map do |token| @@ -248,6 +250,5 @@ module Liquid yield end end - end end diff --git a/lib/liquid/profiler/token.rb b/lib/liquid/token.rb similarity index 99% rename from lib/liquid/profiler/token.rb rename to lib/liquid/token.rb index 8c43da2..3a82014 100644 --- a/lib/liquid/profiler/token.rb +++ b/lib/liquid/token.rb @@ -1,6 +1,5 @@ module Liquid class Token < String - attr_reader :line_number def initialize(content, line_number) @@ -11,6 +10,5 @@ module Liquid def raw "" end - end end diff --git a/test/integration/error_handling_test.rb b/test/integration/error_handling_test.rb index 4f25f81..a66e43c 100644 --- a/test/integration/error_handling_test.rb +++ b/test/integration/error_handling_test.rb @@ -22,6 +22,39 @@ end class ErrorHandlingTest < Minitest::Test include Liquid + def test_templates_parsed_with_line_numbers_renders_them_in_errors + template = <<-LIQUID + Hello, + + {{ errors.standard_error }} will raise a standard error. + + Bla bla test. + + {{ errors.syntax_error }} will raise a syntax error. + + This is an argument error: {{ errors.argument_error }} + + Bla. + LIQUID + + expected = <<-TEXT + Hello, + + Liquid error: 3: standard error will raise a standard error. + + Bla bla test. + + Liquid syntax error: 7: syntax error will raise a syntax error. + + This is an argument error: Liquid error: 9: argument error + + Bla. + TEXT + + output = Liquid::Template.parse(template, line_numbers: true).render('errors' => ErrorDrop.new) + assert_equal expected, output + end + def test_standard_error template = Liquid::Template.parse( ' {{ errors.standard_error }} ' ) assert_equal ' Liquid error: standard error ', template.render('errors' => ErrorDrop.new) @@ -59,7 +92,7 @@ class ErrorHandlingTest < Minitest::Test end end end - + def test_lax_unrecognized_operator template = Liquid::Template.parse(' {% if 1 =! 2 %}ok{% endif %} ', :error_mode => :lax) assert_equal ' Liquid error: Unknown operator =! ', template.render @@ -91,8 +124,8 @@ class ErrorHandlingTest < Minitest::Test # Liquid should not catch Exceptions that are not subclasses of StandardError, like Interrupt and NoMemoryError def test_exceptions_propagate assert_raises Exception do - template = Liquid::Template.parse( ' {{ errors.exception }} ' ) + template = Liquid::Template.parse('{{ errors.exception }}') template.render('errors' => ErrorDrop.new) end end -end # ErrorHandlingTest +end From 3a0ee6ae9180e64f4fd12bbd54418d122fc25f94 Mon Sep 17 00:00:00 2001 From: Tristan Hume Date: Thu, 14 Aug 2014 15:06:54 -0400 Subject: [PATCH 02/12] Remove parser switching duplication --- lib/liquid.rb | 1 + lib/liquid/parser_switching.rb | 30 ++++++++++++++++++++++++++++++ lib/liquid/tag.rb | 25 +------------------------ lib/liquid/variable.rb | 21 ++++++--------------- 4 files changed, 38 insertions(+), 39 deletions(-) create mode 100644 lib/liquid/parser_switching.rb diff --git a/lib/liquid.rb b/lib/liquid.rb index cc56eb0..f719107 100644 --- a/lib/liquid.rb +++ b/lib/liquid.rb @@ -54,6 +54,7 @@ require 'liquid/interrupts' require 'liquid/strainer' require 'liquid/expression' require 'liquid/context' +require 'liquid/parser_switching' require 'liquid/tag' require 'liquid/block' require 'liquid/document' diff --git a/lib/liquid/parser_switching.rb b/lib/liquid/parser_switching.rb new file mode 100644 index 0000000..042419c --- /dev/null +++ b/lib/liquid/parser_switching.rb @@ -0,0 +1,30 @@ +module Liquid + module ParserSwitching + def parse_with_selected_parser(markup) + case @options[:error_mode] || Template.error_mode + when :strict then strict_parse_with_error_context(markup) + when :lax then lax_parse(markup) + when :warn + begin + return strict_parse_with_error_context(markup) + rescue SyntaxError => e + @warnings ||= [] + @warnings << e + return lax_parse(markup) + end + end + end + + private + def strict_parse_with_error_context(markup) + strict_parse(markup) + rescue SyntaxError => e + e.message << markup_context(markup) + raise e + end + + def markup_context(markup) + " in \"#{markup.strip}\"" + end + end +end \ No newline at end of file diff --git a/lib/liquid/tag.rb b/lib/liquid/tag.rb index b4dfec4..d8d35c5 100644 --- a/lib/liquid/tag.rb +++ b/lib/liquid/tag.rb @@ -2,6 +2,7 @@ module Liquid class Tag attr_accessor :options, :line_number attr_reader :nodelist, :warnings + include ParserSwitching class << self def parse(tag_name, markup, tokens, options) @@ -37,29 +38,5 @@ module Liquid def blank? false end - - def parse_with_selected_parser(markup) - case @options[:error_mode] || Template.error_mode - when :strict then strict_parse_with_error_context(markup) - when :lax then lax_parse(markup) - when :warn - begin - return strict_parse_with_error_context(markup) - rescue SyntaxError => e - @warnings ||= [] - @warnings << e - return lax_parse(markup) - end - end - end - - private - - def strict_parse_with_error_context(markup) - strict_parse(markup) - rescue SyntaxError => e - e.message << " in \"#{markup.strip}\"" - raise e - end end end diff --git a/lib/liquid/variable.rb b/lib/liquid/variable.rb index 144b679..04d82fd 100644 --- a/lib/liquid/variable.rb +++ b/lib/liquid/variable.rb @@ -15,30 +15,24 @@ module Liquid EasyParse = /\A *(\w+(?:\.\w+)*) *\z/ attr_accessor :filters, :name, :warnings attr_accessor :line_number + include ParserSwitching def initialize(markup, options = {}) @markup = markup @name = nil @options = options || {} - case @options[:error_mode] || Template.error_mode - when :strict then strict_parse(markup) - when :lax then lax_parse(markup) - when :warn - begin - strict_parse(markup) - rescue SyntaxError => e - @warnings ||= [] - @warnings << e - lax_parse(markup) - end - end + parse_with_selected_parser(markup) end def raw @markup end + def markup_context(markup) + " in \"{{#{markup}}}\"" + end + def lax_parse(markup) @filters = [] if markup =~ /\s*(#{QuotedFragment})(.*)/om @@ -74,9 +68,6 @@ module Liquid @filters << [filtername, filterargs] end p.consume(:end_of_string) - rescue SyntaxError => e - e.message << " in \"{{#{markup}}}\"" - raise e end def parse_filterargs(p) From 27c10193850e511605a07ab3f44ed5048e65314f Mon Sep 17 00:00:00 2001 From: Tristan Hume Date: Thu, 14 Aug 2014 16:23:38 -0400 Subject: [PATCH 03/12] Add line numbers to warnings --- lib/liquid/block.rb | 6 ++++-- lib/liquid/parser_switching.rb | 1 + lib/liquid/token.rb | 4 ++++ test/integration/error_handling_test.rb | 6 ++++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/liquid/block.rb b/lib/liquid/block.rb index a53c282..6d45c71 100644 --- a/lib/liquid/block.rb +++ b/lib/liquid/block.rb @@ -32,7 +32,8 @@ module Liquid # fetch the tag from registered blocks if tag = Template.tags[$1] - new_tag = tag.parse($1, $2, tokens, @options) + markup = token.is_a?(Token) ? token.child($2) : $2 + new_tag = tag.parse($1, markup, tokens, @options) new_tag.line_number = token.line_number if token.is_a?(Token) @blank &&= new_tag.blank? @nodelist << new_tag @@ -103,7 +104,8 @@ module Liquid def create_variable(token) token.scan(ContentOfVariable) do |content| - return Variable.new(content.first, @options) + markup = token.is_a?(Token) ? token.child(content.first) : content.first + return Variable.new(markup, @options) end raise SyntaxError.new(options[:locale].t("errors.syntax.variable_termination".freeze, :token => token, :tag_end => VariableEnd.inspect)) end diff --git a/lib/liquid/parser_switching.rb b/lib/liquid/parser_switching.rb index 042419c..288fe7f 100644 --- a/lib/liquid/parser_switching.rb +++ b/lib/liquid/parser_switching.rb @@ -8,6 +8,7 @@ module Liquid begin return strict_parse_with_error_context(markup) rescue SyntaxError => e + e.line_number = markup.line_number if markup.is_a?(Token) @warnings ||= [] @warnings << e return lax_parse(markup) diff --git a/lib/liquid/token.rb b/lib/liquid/token.rb index 3a82014..acf8ef9 100644 --- a/lib/liquid/token.rb +++ b/lib/liquid/token.rb @@ -10,5 +10,9 @@ module Liquid def raw "" end + + def child(string) + Token.new(string, @line_number) + end end end diff --git a/test/integration/error_handling_test.rb b/test/integration/error_handling_test.rb index a66e43c..6bc2c23 100644 --- a/test/integration/error_handling_test.rb +++ b/test/integration/error_handling_test.rb @@ -121,6 +121,12 @@ class ErrorHandlingTest < Minitest::Test assert_equal '', template.render end + def test_warning_line_numbers + template = Liquid::Template.parse("{% if ~~~ %}\n{{%%%}}{% else %}\n{{ hello. }}{% endif %}", :error_mode => :warn, :line_numbers => true) + assert_equal 3, template.warnings.size + assert_equal [1,2,3], template.warnings.map(&:line_number) + end + # Liquid should not catch Exceptions that are not subclasses of StandardError, like Interrupt and NoMemoryError def test_exceptions_propagate assert_raises Exception do From 17cc8fdbb36178c2c53a14e6db2d1bd93649d043 Mon Sep 17 00:00:00 2001 From: Florian Weingarten Date: Wed, 20 Aug 2014 16:45:11 +0000 Subject: [PATCH 04/12] put line number in parentheses --- lib/liquid/context.rb | 4 ++-- lib/liquid/errors.rb | 15 ++++++--------- lib/liquid/parser_switching.rb | 4 ++-- test/integration/error_handling_test.rb | 6 +++--- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/liquid/context.rb b/lib/liquid/context.rb index 0df9f77..8348150 100644 --- a/lib/liquid/context.rb +++ b/lib/liquid/context.rb @@ -92,8 +92,8 @@ module Liquid end - def handle_error(e, token) - e = Liquid::Error.error_with_line_number(e, token) + def handle_error(e, token=nil) + e = Liquid::Error.error_from_token(e, token) if token errors.push(e) raise if exception_handler && exception_handler.call(e) Liquid::Error.render(e) diff --git a/lib/liquid/errors.rb b/lib/liquid/errors.rb index da03886..6de2cc2 100644 --- a/lib/liquid/errors.rb +++ b/lib/liquid/errors.rb @@ -4,24 +4,21 @@ module Liquid def self.render(e) msg = if e.is_a?(Liquid::Error) && e.line_number - "#{e.line_number}: #{e.message}" + " (line #{e.line_number}): #{e.message}" else - e.message + ": #{e.message}" end case e when SyntaxError - "Liquid syntax error: #{msg}" + "Liquid syntax error" << msg else - "Liquid error: #{msg}" + "Liquid error" << msg end end - def self.error_with_line_number(e, token) - if e.is_a?(Liquid::Error) - e.set_line_number_from_token(token) - end - + def self.error_from_token(e, token) + e.set_line_number_from_token(token) if e.is_a?(Liquid::Error) e end diff --git a/lib/liquid/parser_switching.rb b/lib/liquid/parser_switching.rb index 288fe7f..5c82063 100644 --- a/lib/liquid/parser_switching.rb +++ b/lib/liquid/parser_switching.rb @@ -8,7 +8,7 @@ module Liquid begin return strict_parse_with_error_context(markup) rescue SyntaxError => e - e.line_number = markup.line_number if markup.is_a?(Token) + e.set_line_number_from_token(markup) @warnings ||= [] @warnings << e return lax_parse(markup) @@ -28,4 +28,4 @@ module Liquid " in \"#{markup.strip}\"" end end -end \ No newline at end of file +end diff --git a/test/integration/error_handling_test.rb b/test/integration/error_handling_test.rb index 6bc2c23..61850fd 100644 --- a/test/integration/error_handling_test.rb +++ b/test/integration/error_handling_test.rb @@ -40,13 +40,13 @@ class ErrorHandlingTest < Minitest::Test expected = <<-TEXT Hello, - Liquid error: 3: standard error will raise a standard error. + Liquid error (line 3): standard error will raise a standard error. Bla bla test. - Liquid syntax error: 7: syntax error will raise a syntax error. + Liquid syntax error (line 7): syntax error will raise a syntax error. - This is an argument error: Liquid error: 9: argument error + This is an argument error: Liquid error (line 9): argument error Bla. TEXT From 60d8a213a57782dd0e76fe3b9a531e6ef58cbe87 Mon Sep 17 00:00:00 2001 From: Florian Weingarten Date: Wed, 20 Aug 2014 17:12:34 +0000 Subject: [PATCH 05/12] Clean up Liquid::Error#render --- lib/liquid/errors.rb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/liquid/errors.rb b/lib/liquid/errors.rb index 6de2cc2..3aec4a1 100644 --- a/lib/liquid/errors.rb +++ b/lib/liquid/errors.rb @@ -3,18 +3,21 @@ module Liquid attr_accessor :line_number def self.render(e) - msg = if e.is_a?(Liquid::Error) && e.line_number - " (line #{e.line_number}): #{e.message}" + str = "" + + if e.is_a?(SyntaxError) + str << "Liquid syntax error" else - ": #{e.message}" + str << "Liquid error" end - case e - when SyntaxError - "Liquid syntax error" << msg - else - "Liquid error" << msg + if e.respond_to?(:line_number) && e.line_number + str << " (line #{e.line_number})" end + + str << ": " + str << e.message + str end def self.error_from_token(e, token) From aabbd8f1a16003c9335c14ee3cc5e5eda822239f Mon Sep 17 00:00:00 2001 From: Florian Weingarten Date: Wed, 20 Aug 2014 17:15:14 +0000 Subject: [PATCH 06/12] remove unnecessary method --- lib/liquid/context.rb | 5 ++++- lib/liquid/errors.rb | 5 ----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/liquid/context.rb b/lib/liquid/context.rb index 8348150..8e58b1d 100644 --- a/lib/liquid/context.rb +++ b/lib/liquid/context.rb @@ -93,7 +93,10 @@ module Liquid def handle_error(e, token=nil) - e = Liquid::Error.error_from_token(e, token) if token + if e.is_a?(Liquid::Error) + e.set_line_number_from_token(token) + end + errors.push(e) raise if exception_handler && exception_handler.call(e) Liquid::Error.render(e) diff --git a/lib/liquid/errors.rb b/lib/liquid/errors.rb index 3aec4a1..cac3910 100644 --- a/lib/liquid/errors.rb +++ b/lib/liquid/errors.rb @@ -20,11 +20,6 @@ module Liquid str end - def self.error_from_token(e, token) - e.set_line_number_from_token(token) if e.is_a?(Liquid::Error) - e - end - def set_line_number_from_token(token) return unless token.respond_to?(:line_number) self.line_number = token.line_number From c83e1c7b6dbe1e9463b9ab6827254c676243cb1a Mon Sep 17 00:00:00 2001 From: Florian Weingarten Date: Wed, 20 Aug 2014 17:36:48 +0000 Subject: [PATCH 07/12] prefix for Liquid::Error instances --- lib/liquid/errors.rb | 44 ++++++++++++++++++------- lib/liquid/parser_switching.rb | 4 +-- lib/liquid/variable.rb | 2 +- test/integration/error_handling_test.rb | 13 +++++--- 4 files changed, 44 insertions(+), 19 deletions(-) diff --git a/lib/liquid/errors.rb b/lib/liquid/errors.rb index cac3910..44f89bc 100644 --- a/lib/liquid/errors.rb +++ b/lib/liquid/errors.rb @@ -1,22 +1,18 @@ module Liquid class Error < ::StandardError attr_accessor :line_number + attr_accessor :markup_context - def self.render(e) + def to_s(with_prefix=true) str = "" + str << message_prefix if with_prefix + str << super() - if e.is_a?(SyntaxError) - str << "Liquid syntax error" - else - str << "Liquid error" + if markup_context + str << " " + str << markup_context end - if e.respond_to?(:line_number) && e.line_number - str << " (line #{e.line_number})" - end - - str << ": " - str << e.message str end @@ -24,6 +20,32 @@ module Liquid return unless token.respond_to?(:line_number) self.line_number = token.line_number end + + def self.render(e) + if e.is_a?(Liquid::Error) + e.to_s + else + "Liquid error: #{e.to_s}" + end + end + + private + + def message_prefix + str = "" + if is_a?(SyntaxError) + str << "Liquid syntax error" + else + str << "Liquid error" + end + + if line_number + str << " (line #{line_number})" + end + + str << ": " + str + end end class ArgumentError < Error; end diff --git a/lib/liquid/parser_switching.rb b/lib/liquid/parser_switching.rb index 5c82063..9dd19db 100644 --- a/lib/liquid/parser_switching.rb +++ b/lib/liquid/parser_switching.rb @@ -20,12 +20,12 @@ module Liquid def strict_parse_with_error_context(markup) strict_parse(markup) rescue SyntaxError => e - e.message << markup_context(markup) + e.markup_context = markup_context(markup) raise e end def markup_context(markup) - " in \"#{markup.strip}\"" + "in \"#{markup.strip}\"" end end end diff --git a/lib/liquid/variable.rb b/lib/liquid/variable.rb index 04d82fd..1282a2b 100644 --- a/lib/liquid/variable.rb +++ b/lib/liquid/variable.rb @@ -30,7 +30,7 @@ module Liquid end def markup_context(markup) - " in \"{{#{markup}}}\"" + "in \"{{#{markup}}}\"" end def lax_parse(markup) diff --git a/test/integration/error_handling_test.rb b/test/integration/error_handling_test.rb index 61850fd..ee07204 100644 --- a/test/integration/error_handling_test.rb +++ b/test/integration/error_handling_test.rb @@ -104,25 +104,28 @@ class ErrorHandlingTest < Minitest::Test err = assert_raises(SyntaxError) do Liquid::Template.parse(' {% if 1 =! 2 %}ok{% endif %} ', :error_mode => :strict) end - assert_equal 'Unexpected character = in "1 =! 2"', err.message + assert_equal 'Liquid syntax error: Unexpected character = in "1 =! 2"', err.message err = assert_raises(SyntaxError) do Liquid::Template.parse('{{%%%}}', :error_mode => :strict) end - assert_equal 'Unexpected character % in "{{%%%}}"', err.message + assert_equal 'Liquid syntax error: Unexpected character % in "{{%%%}}"', err.message end def test_warnings template = Liquid::Template.parse('{% if ~~~ %}{{%%%}}{% else %}{{ hello. }}{% endif %}', :error_mode => :warn) assert_equal 3, template.warnings.size - assert_equal 'Unexpected character ~ in "~~~"', template.warnings[0].message - assert_equal 'Unexpected character % in "{{%%%}}"', template.warnings[1].message - assert_equal 'Expected id but found end_of_string in "{{ hello. }}"', template.warnings[2].message + assert_equal 'Unexpected character ~ in "~~~"', template.warnings[0].to_s(false) + assert_equal 'Unexpected character % in "{{%%%}}"', template.warnings[1].to_s(false) + assert_equal 'Expected id but found end_of_string in "{{ hello. }}"', template.warnings[2].to_s(false) assert_equal '', template.render end def test_warning_line_numbers template = Liquid::Template.parse("{% if ~~~ %}\n{{%%%}}{% else %}\n{{ hello. }}{% endif %}", :error_mode => :warn, :line_numbers => true) + assert_equal 'Liquid syntax error (line 1): Unexpected character ~ in "~~~"', template.warnings[0].message + assert_equal 'Liquid syntax error (line 2): Unexpected character % in "{{%%%}}"', template.warnings[1].message + assert_equal 'Liquid syntax error (line 3): Expected id but found end_of_string in "{{ hello. }}"', template.warnings[2].message assert_equal 3, template.warnings.size assert_equal [1,2,3], template.warnings.map(&:line_number) end From c60fd0715d9ba6e41df3611dc713480ecd0c422b Mon Sep 17 00:00:00 2001 From: Florian Weingarten Date: Wed, 20 Aug 2014 17:45:24 +0000 Subject: [PATCH 08/12] remove unnecessary nil --- lib/liquid/template.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/liquid/template.rb b/lib/liquid/template.rb index 8a496e1..273d5c3 100644 --- a/lib/liquid/template.rb +++ b/lib/liquid/template.rb @@ -199,7 +199,7 @@ module Liquid end result.respond_to?(:join) ? result.join : result rescue Liquid::MemoryError => e - context.handle_error(e, nil) + context.handle_error(e) ensure @errors = context.errors end From 939365c234e00152a2cbc8c4b5d711638bfba13a Mon Sep 17 00:00:00 2001 From: Florian Weingarten Date: Thu, 21 Aug 2014 14:35:57 +0000 Subject: [PATCH 09/12] move line number check --- lib/liquid/template.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/liquid/template.rb b/lib/liquid/template.rb index 273d5c3..3c0a672 100644 --- a/lib/liquid/template.rb +++ b/lib/liquid/template.rb @@ -106,7 +106,7 @@ module Liquid @options = options @profiling = options[:profile] @profiling = options.delete(:profile) - @line_numbers = options.delete(:line_numbers) || @profiling + @line_numbers = options.delete(:line_numbers) @root = Document.parse(tokenize(source), DEFAULT_OPTIONS.merge(options)) @warnings = nil self @@ -226,7 +226,7 @@ module Liquid end def calculate_line_numbers(raw_tokens) - return raw_tokens unless @line_numbers + return raw_tokens unless @line_numbers || @profiling current_line = 1 raw_tokens.map do |token| From ce06ed4bb141c7c41bc73375cb3a1d3bfbf587c2 Mon Sep 17 00:00:00 2001 From: Florian Weingarten Date: Fri, 5 Sep 2014 14:16:20 +0000 Subject: [PATCH 10/12] merge conflicts --- lib/liquid/parser_switching.rb | 2 +- lib/liquid/template.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/liquid/parser_switching.rb b/lib/liquid/parser_switching.rb index 9dd19db..5fc0f38 100644 --- a/lib/liquid/parser_switching.rb +++ b/lib/liquid/parser_switching.rb @@ -25,7 +25,7 @@ module Liquid end def markup_context(markup) - "in \"#{markup.strip}\"" + "in \"#{markup.strip}\"" end end end diff --git a/lib/liquid/template.rb b/lib/liquid/template.rb index 3c0a672..4b5052c 100644 --- a/lib/liquid/template.rb +++ b/lib/liquid/template.rb @@ -105,7 +105,6 @@ module Liquid def parse(source, options = {}) @options = options @profiling = options[:profile] - @profiling = options.delete(:profile) @line_numbers = options.delete(:line_numbers) @root = Document.parse(tokenize(source), DEFAULT_OPTIONS.merge(options)) @warnings = nil From debac5dd0bb677d2ce1f51d8c5d9f0c862854db4 Mon Sep 17 00:00:00 2001 From: Florian Weingarten Date: Sat, 6 Sep 2014 10:15:25 -0400 Subject: [PATCH 11/12] Revert "move line number check" This reverts commit 939365c234e00152a2cbc8c4b5d711638bfba13a. Conflicts: lib/liquid/template.rb --- lib/liquid/template.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/liquid/template.rb b/lib/liquid/template.rb index 4b5052c..5755722 100644 --- a/lib/liquid/template.rb +++ b/lib/liquid/template.rb @@ -105,7 +105,7 @@ module Liquid def parse(source, options = {}) @options = options @profiling = options[:profile] - @line_numbers = options.delete(:line_numbers) + @line_numbers = options[:line_numbers] || @profiling @root = Document.parse(tokenize(source), DEFAULT_OPTIONS.merge(options)) @warnings = nil self @@ -225,7 +225,7 @@ module Liquid end def calculate_line_numbers(raw_tokens) - return raw_tokens unless @line_numbers || @profiling + return raw_tokens unless @line_numbers current_line = 1 raw_tokens.map do |token| From aafdf4adb0ee790e827b4102a2f482d032b6ad0e Mon Sep 17 00:00:00 2001 From: Jason Hiltz-Laforge Date: Mon, 8 Sep 2014 20:41:22 +0000 Subject: [PATCH 12/12] Fix JRuby builds --- test/integration/tags/include_tag_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/tags/include_tag_test.rb b/test/integration/tags/include_tag_test.rb index 8c45a8f..49267f3 100644 --- a/test/integration/tags/include_tag_test.rb +++ b/test/integration/tags/include_tag_test.rb @@ -132,7 +132,7 @@ class IncludeTagTest < Minitest::Test Liquid::Template.file_system = infinite_file_system.new - assert_raises(Liquid::StackLevelError) do + assert_raises(Liquid::StackLevelError, SystemStackError) do Template.parse("{% include 'loop' %}").render! end