Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/liquid/condition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def liquid_blank?(value)
false
when String
# Blank if empty or whitespace only (matches ActiveSupport)
value.empty? || value.match?(/\A\s*\z/)
value.empty? || value.match?(/\A[[:space:]]*\z/)
when Array, Hash
value.empty?
else
Expand Down
11 changes: 11 additions & 0 deletions test/unit/condition_unit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,17 @@ def test_blank_with_whitespace_string
assert_evaluates_true(VariableLookup.new('whitespace'), '==', blank_literal)
end

def test_blank_with_unicode_whitespace_string
# ActiveSupport's String#blank? matches /\A[[:space:]]*\z/, so Unicode
# whitespace such as a non-breaking space or an ideographic space is blank.
blank_literal = Condition.class_variable_get(:@@method_literals)['blank']

["\u00A0", "\u3000", "\u2003 \n"].each do |value|
@context['unicode_whitespace'] = value
assert_evaluates_true(VariableLookup.new('unicode_whitespace'), '==', blank_literal)
end
end

def test_blank_with_empty_string
# An empty string has no content, so it should be considered blank.
# This is the most basic case of a blank string.
Expand Down
Loading