Compare commits

...

8 Commits

Author SHA1 Message Date
Mbarak Bujra
efec04af06 add a test clearly showing and commiting to the order of and/or operations 2021-04-05 20:55:10 +00:00
Dylan Thacker-Smith
eab13a07d9 Add changelog entry for a recent fix 2021-03-29 13:43:01 -07:00
Dylan Thacker-Smith
ca96ca0fef Fix support for using a String subclass for the liquid source (#1421) 2021-03-29 16:22:05 -04:00
Marc-André Cournoyer
4e7a953e73 Merge pull request #1417 from Shopify/prep-release
Bump to 5.0.1 and add changelog for release
2021-03-24 16:55:10 -04:00
Marc-André Cournoyer
6ac2499f7f Remove internal tokenizer fix from History.md
Co-authored-by: Dylan Thacker-Smith <dylan.smith@shopify.com>
2021-03-24 16:53:45 -04:00
Marc-André Cournoyer
ff70161512 Remove internal fixes from History.md
Co-authored-by: Dylan Thacker-Smith <dylan.smith@shopify.com>
2021-03-24 16:52:57 -04:00
Marc-André Cournoyer
026157e128 Bump to 5.0.1 and add changelog for release 2021-03-24 16:19:19 -04:00
Charles-Philippe Clermont
bf64239ea6 Merge pull request #1414 from Shopify/fix/echo-parse-tree-visitor
Add ParseTreeVisitor to Echo tag
2021-03-24 09:38:48 -04:00
5 changed files with 77 additions and 3 deletions

View File

@@ -1,5 +1,20 @@
# Liquid Change Log
## 5.0.2 (unreleased)
### Fixes
* Fix support for using a String subclass for the liquid source (#1421) [Dylan Thacker-Smith]
## 5.0.1 / 2021-03-24
### Fixes
* Add ParseTreeVisitor to Echo tag (#1414) [CP Clermont]
* Test with ruby 3.0 as the latest ruby version (#1398) [Dylan Thacker-Smith]
* Handle carriage return in newlines_to_br (#1391) [Unending]
### Performance Improvements
* Use split limit in truncatewords (#1361) [Dylan Thacker-Smith]
## 5.0.0 / 2021-01-06
### Features

View File

@@ -5,7 +5,7 @@ module Liquid
attr_reader :line_number, :for_liquid_tag
def initialize(source, line_numbers = false, line_number: nil, for_liquid_tag: false)
@source = source
@source = source.to_s.to_str
@line_number = line_number || (line_numbers ? 1 : nil)
@for_liquid_tag = for_liquid_tag
@tokens = tokenize
@@ -24,7 +24,7 @@ module Liquid
private
def tokenize
return [] if @source.to_s.empty?
return [] if @source.empty?
return @source.split("\n") if @for_liquid_tag

View File

@@ -2,5 +2,5 @@
# frozen_string_literal: true
module Liquid
VERSION = "5.0.0"
VERSION = "5.0.2.alpha"
end

View File

@@ -187,4 +187,49 @@ class IfElseTagTest < Minitest::Test
assert_template_result(expected.to_s, tpl, assigns, assigns.to_s)
end
end
def test_operators_order
expected_groupings = [
->(w, x, y, z) { (w && (x || (y && z))) },
->(w, x, y, z) { (w || (x && (y || z))) },
]
liquid_conditions = [
'w and x or y and z',
'w or x and y or z',
]
conditions = (0..0b1111).map do |cond|
[
(cond & 0b1000) == 0 ? false : true,
(cond & 0b0100) == 0 ? false : true,
(cond & 0b0010) == 0 ? false : true,
(cond & 0b0001) == 0 ? false : true,
]
end
expected_results = expected_groupings.map do |test|
conditions.map do |condition|
test.call(*condition)
end
end
liquid_results = liquid_conditions.map do |conditional_expression|
tpl = "{% if #{conditional_expression} %}true{% else %}false{% endif %}"
template = Liquid::Template.parse(tpl, line_numbers: true)
conditions.map do |condition|
w, x, y, z = condition
assigns = { 'w' => w, 'x' => x, 'y' => y, 'z' => z }
template.render!(assigns)
end.map { |r| true?(r) }
end
assert_equal(expected_results, liquid_results)
end
private
def true?(obj)
obj.to_s.casecmp('true').zero?
end
end

View File

@@ -323,4 +323,18 @@ class TemplateTest < Minitest::Test
result = t.render('x' => 1, 'y' => 5)
assert_equal('12345', result)
end
def test_source_string_subclass
string_subclass = Class.new(String) do
# E.g. ActiveSupport::SafeBuffer does this, so don't just rely on to_s to return a String
def to_s
self
end
end
source = string_subclass.new("{% assign x = 2 -%} x= {{- x }}")
assert_instance_of(string_subclass, source)
output = Template.parse(source).render!
assert_equal("x=2", output)
assert_instance_of(String, output)
end
end