From ff829e7996de0202e7284ec4a9304d02fd04ca7c Mon Sep 17 00:00:00 2001 From: James MacAulay Date: Wed, 7 Jul 2010 16:48:23 -0400 Subject: [PATCH] fix if tag parsing with expressions starting with and/or --- lib/liquid/tags/if.rb | 2 +- test/if_else_test.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/liquid/tags/if.rb b/lib/liquid/tags/if.rb index 608d11a..f060000 100644 --- a/lib/liquid/tags/if.rb +++ b/lib/liquid/tags/if.rb @@ -14,7 +14,7 @@ module Liquid class If < Block SyntaxHelp = "Syntax Error in tag 'if' - Valid syntax: if [expression]" Syntax = /(#{QuotedFragment})\s*([=!<>a-z_]+)?\s*(#{QuotedFragment})?/ - ExpressionsAndOperators = /(?:and|or|(?:\s*(?!\b(?:and|or)\b)(?:#{QuotedFragment}|\S+)\s*)+)/ + ExpressionsAndOperators = /(?:\b(?:and|or)\b|(?:\s*(?!\b(?:and|or)\b)(?:#{QuotedFragment}|\S+)\s*)+)/ def initialize(tag_name, markup, tokens) diff --git a/test/if_else_test.rb b/test/if_else_test.rb index 629dd12..2a8c1ad 100644 --- a/test/if_else_test.rb +++ b/test/if_else_test.rb @@ -44,6 +44,20 @@ class IfElseTest < Test::Unit::TestCase end end + def test_comparison_of_expressions_starting_with_and_or_or + assigns = {'order' => {'items_count' => 0}, 'android' => {'name' => 'Roy'}} + assert_nothing_raised do + assert_template_result( "YES", + "{% if android.name == 'Roy' %}YES{% endif %}", + assigns) + end + assert_nothing_raised do + assert_template_result( "YES", + "{% if order.items_count == 0 %}YES{% endif %}", + assigns) + end + end + def test_if_and assert_template_result(' YES ','{% if true and true %} YES {% endif %}') assert_template_result('','{% if false and true %} YES {% endif %}')