Skip to content

Commit

Permalink
Fix false negative on compact test found after fixes on first filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
hugopl committed Jan 19, 2023
1 parent 0917370 commit ad3f152
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
1 change: 0 additions & 1 deletion spec/integration/golden_liquid.pending
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ liquid.golden.base64_url_safe_encode_filter from string
liquid.golden.base64_url_safe_encode_filter from string with URL unsafe
liquid.golden.base64_url_safe_encode_filter not a string
liquid.golden.base64_url_safe_encode_filter unexpected argument
liquid.golden.compact_filter left value is not an array
liquid.golden.concat_filter left value contains non string
liquid.golden.concat_filter left value is not array-like
liquid.golden.concat_filter missing argument is an error
Expand Down
9 changes: 5 additions & 4 deletions src/liquid/filters/compact.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ module Liquid::Filters
def self.filter(data : Any, args : Array(Any), options : Hash(String, Any)) : Any
raise FilterArgumentException.new("compact filter expects at most 1 argument.") if args.size > 1

array = data.as_a?
return data if array.nil?
raw_data = data.raw
return Any.new(nil) if raw_data.nil?
return Any{data} unless raw_data.is_a?(Enumerable(Any))

key = args.first?
return Any.new(array.reject(&.raw.nil?)) if key.nil? || !key.as_s?
return Any.new(raw_data.reject(&.raw.nil?)) if key.nil? || !key.as_s?

key = key.as_s
result = array.reject do |item|
result = raw_data.reject do |item|
raw_item = item.raw
if raw_item.is_a?(Drop) || raw_item.is_a?(Hash)
raw_item[key].raw.nil?
Expand Down

0 comments on commit ad3f152

Please # to comment.