liquid 5.7.0 → 5.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.md +13 -1
- data/lib/liquid/lexer.rb +6 -0
- data/lib/liquid/standardfilters.rb +14 -39
- data/lib/liquid/tokenizer.rb +6 -0
- data/lib/liquid/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 914cff799e3bd2ac8b59184ae521d8b8eccce15ee3d0dac103e471bcab5f1255
|
4
|
+
data.tar.gz: 38b104ec712e953540ab7316ce2e4cfac13a5964f5bc32ca39bc1252b908ac43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7c7f4e17b845a60ef8d7e2bf21b5378f5c116806ca62bb5f310b595275b3080294e378ea57bf2d70f35809ff4570142ccc77a62f0ac1c0afdd629ae6b1a5980
|
7
|
+
data.tar.gz: 48b4101e4e4c293ae10ef34ef701c8fcc3bbf764a55eca7b5a1022b95fa8f7e64d13f1e7ecc9cae5f456c12f30de9172baed90016de088384ec6847950a711b4
|
data/History.md
CHANGED
@@ -1,10 +1,22 @@
|
|
1
1
|
# Liquid Change Log
|
2
2
|
|
3
|
-
## 5.
|
3
|
+
## 5.7.3 (unreleased)
|
4
|
+
|
5
|
+
* Raise Liquid::SyntaxError when parsing invalidly encoded strings
|
6
|
+
|
7
|
+
## 5.7.2 2025-01-31
|
8
|
+
|
9
|
+
* Fix array filters to not support nested properties
|
10
|
+
|
11
|
+
## 5.7.1 2025-01-24
|
12
|
+
|
13
|
+
* Fix the `find` and `find_index`filters to return `nil` when filtering empty arrays
|
14
|
+
* Fix the `has` filter to return `false` when filtering empty arrays
|
4
15
|
|
5
16
|
## 5.7.0 2025-01-16
|
6
17
|
|
7
18
|
### Features
|
19
|
+
|
8
20
|
* Add `find`, `find_index`, `has`, and `reject` filters to arrays
|
9
21
|
* Compatibility with Ruby 3.4
|
10
22
|
|
data/lib/liquid/lexer.rb
CHANGED
@@ -161,6 +161,12 @@ module Liquid
|
|
161
161
|
end
|
162
162
|
# rubocop:enable Metrics/BlockNesting
|
163
163
|
output << EOS
|
164
|
+
rescue ::ArgumentError => e
|
165
|
+
if e.message == "invalid byte sequence in #{ss.string.encoding}"
|
166
|
+
raise SyntaxError, "Invalid byte sequence in #{ss.string.encoding}"
|
167
|
+
else
|
168
|
+
raise
|
169
|
+
end
|
164
170
|
end
|
165
171
|
|
166
172
|
def raise_syntax_error(start_pos, ss)
|
@@ -387,7 +387,7 @@ module Liquid
|
|
387
387
|
end
|
388
388
|
elsif ary.all? { |el| el.respond_to?(:[]) }
|
389
389
|
begin
|
390
|
-
ary.sort { |a, b| nil_safe_compare(
|
390
|
+
ary.sort { |a, b| nil_safe_compare(a[property], b[property]) }
|
391
391
|
rescue TypeError
|
392
392
|
raise_property_error(property)
|
393
393
|
end
|
@@ -416,7 +416,7 @@ module Liquid
|
|
416
416
|
end
|
417
417
|
elsif ary.all? { |el| el.respond_to?(:[]) }
|
418
418
|
begin
|
419
|
-
ary.sort { |a, b| nil_safe_casecmp(
|
419
|
+
ary.sort { |a, b| nil_safe_casecmp(a[property], b[property]) }
|
420
420
|
rescue TypeError
|
421
421
|
raise_property_error(property)
|
422
422
|
end
|
@@ -456,10 +456,10 @@ module Liquid
|
|
456
456
|
# Tests if any item in an array has a specific property value.
|
457
457
|
# @liquid_description
|
458
458
|
# This requires you to provide both the property name and the associated value.
|
459
|
-
# @liquid_syntax array |
|
459
|
+
# @liquid_syntax array | has: string, string
|
460
460
|
# @liquid_return [boolean]
|
461
461
|
def has(input, property, target_value = nil)
|
462
|
-
filter_array(input, property, target_value) { |ary, &block| ary.any?(&block) }
|
462
|
+
filter_array(input, property, target_value, false) { |ary, &block| ary.any?(&block) }
|
463
463
|
end
|
464
464
|
|
465
465
|
# @liquid_public_docs
|
@@ -472,7 +472,7 @@ module Liquid
|
|
472
472
|
# @liquid_syntax array | find: string, string
|
473
473
|
# @liquid_return [untyped]
|
474
474
|
def find(input, property, target_value = nil)
|
475
|
-
filter_array(input, property, target_value) { |ary, &block| ary.find(&block) }
|
475
|
+
filter_array(input, property, target_value, nil) { |ary, &block| ary.find(&block) }
|
476
476
|
end
|
477
477
|
|
478
478
|
# @liquid_public_docs
|
@@ -485,7 +485,7 @@ module Liquid
|
|
485
485
|
# @liquid_syntax array | find_index: string, string
|
486
486
|
# @liquid_return [number]
|
487
487
|
def find_index(input, property, target_value = nil)
|
488
|
-
filter_array(input, property, target_value) { |ary, &block| ary.find_index(&block) }
|
488
|
+
filter_array(input, property, target_value, nil) { |ary, &block| ary.find_index(&block) }
|
489
489
|
end
|
490
490
|
|
491
491
|
# @liquid_public_docs
|
@@ -504,7 +504,7 @@ module Liquid
|
|
504
504
|
[]
|
505
505
|
else
|
506
506
|
ary.uniq do |item|
|
507
|
-
|
507
|
+
item[property]
|
508
508
|
rescue TypeError
|
509
509
|
raise_property_error(property)
|
510
510
|
rescue NoMethodError
|
@@ -540,7 +540,7 @@ module Liquid
|
|
540
540
|
if property == "to_liquid"
|
541
541
|
e
|
542
542
|
elsif e.respond_to?(:[])
|
543
|
-
r =
|
543
|
+
r = e[property]
|
544
544
|
r.is_a?(Proc) ? r.call : r
|
545
545
|
end
|
546
546
|
end
|
@@ -564,7 +564,7 @@ module Liquid
|
|
564
564
|
[]
|
565
565
|
else
|
566
566
|
ary.reject do |item|
|
567
|
-
|
567
|
+
item[property].nil?
|
568
568
|
rescue TypeError
|
569
569
|
raise_property_error(property)
|
570
570
|
rescue NoMethodError
|
@@ -950,7 +950,7 @@ module Liquid
|
|
950
950
|
if property.nil?
|
951
951
|
item
|
952
952
|
elsif item.respond_to?(:[])
|
953
|
-
|
953
|
+
item[property]
|
954
954
|
else
|
955
955
|
0
|
956
956
|
end
|
@@ -969,16 +969,16 @@ module Liquid
|
|
969
969
|
|
970
970
|
attr_reader :context
|
971
971
|
|
972
|
-
def filter_array(input, property, target_value, &block)
|
972
|
+
def filter_array(input, property, target_value, default_value = [], &block)
|
973
973
|
ary = InputIterator.new(input, context)
|
974
974
|
|
975
|
-
return
|
975
|
+
return default_value if ary.empty?
|
976
976
|
|
977
977
|
block.call(ary) do |item|
|
978
978
|
if target_value.nil?
|
979
|
-
|
979
|
+
item[property]
|
980
980
|
else
|
981
|
-
|
981
|
+
item[property] == target_value
|
982
982
|
end
|
983
983
|
rescue TypeError
|
984
984
|
raise_property_error(property)
|
@@ -988,31 +988,6 @@ module Liquid
|
|
988
988
|
end
|
989
989
|
end
|
990
990
|
|
991
|
-
def fetch_property(drop, property_or_keys)
|
992
|
-
##
|
993
|
-
# This keeps backward compatibility by supporting properties containing
|
994
|
-
# dots. This is valid in Liquid syntax and used in some runtimes, such as
|
995
|
-
# Shopify with metafields.
|
996
|
-
#
|
997
|
-
# Using this approach, properties like 'price.value' can be accessed in
|
998
|
-
# both of the following examples:
|
999
|
-
#
|
1000
|
-
# ```
|
1001
|
-
# [
|
1002
|
-
# { 'name' => 'Item 1', 'price.price' => 40000 },
|
1003
|
-
# { 'name' => 'Item 2', 'price' => { 'value' => 39900 } }
|
1004
|
-
# ]
|
1005
|
-
# ```
|
1006
|
-
value = drop[property_or_keys]
|
1007
|
-
|
1008
|
-
return value if !value.nil? || !property_or_keys.is_a?(String)
|
1009
|
-
|
1010
|
-
keys = property_or_keys.split('.')
|
1011
|
-
keys.reduce(drop) do |drop, key|
|
1012
|
-
drop.respond_to?(:[]) ? drop[key] : drop
|
1013
|
-
end
|
1014
|
-
end
|
1015
|
-
|
1016
991
|
def raise_property_error(property)
|
1017
992
|
raise Liquid::ArgumentError, "cannot select the property '#{property}'"
|
1018
993
|
end
|
data/lib/liquid/tokenizer.rb
CHANGED
@@ -103,6 +103,12 @@ module Liquid
|
|
103
103
|
|
104
104
|
pos = @ss.pos -= 2
|
105
105
|
@source.byteslice(start, pos - start)
|
106
|
+
rescue ::ArgumentError => e
|
107
|
+
if e.message == "invalid byte sequence in #{@ss.string.encoding}"
|
108
|
+
raise SyntaxError, "Invalid byte sequence in #{@ss.string.encoding}"
|
109
|
+
else
|
110
|
+
raise
|
111
|
+
end
|
106
112
|
end
|
107
113
|
|
108
114
|
def next_variable_token
|
data/lib/liquid/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: liquid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.7.
|
4
|
+
version: 5.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Lütke
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-02-24 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: strscan
|
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: 1.3.7
|
160
160
|
requirements: []
|
161
|
-
rubygems_version: 3.6.
|
161
|
+
rubygems_version: 3.6.3
|
162
162
|
specification_version: 4
|
163
163
|
summary: A secure, non-evaling end user template engine with aesthetic markup.
|
164
164
|
test_files: []
|