WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit e903b59

Browse files
Make sure logic less conditionals also check empty state.
In the documentation of the conditional it is stated that "If the object is not false or empty?, the content will show", but before this commit, we didn't check on `empty?`. Especially combined with the inverted conditional (where `empty?` is actually checked), this is very confusing, because this means a value can be true and false at the same time.
1 parent 00217e1 commit e903b59

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/slim/logic_less/context.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def lambda(name)
2727
end
2828

2929
def section(name)
30-
if dict = scope[name]
30+
dict = scope[name]
31+
if dict && !(dict.respond_to?(:empty?) && dict.empty?)
3132
if !dict.respond_to?(:has_key?) && dict.respond_to?(:each)
3233
new_scope do
3334
dict.each do |d|

test/logic_less/test_logic_less.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,17 @@ def test_conditional_parent
302302
assert_html'<li class="previous"><a href="prev">Older</a></li><li class="next"><a href="next">Newer</a></li>', source, scope: {prev_page: 'prev', next_page: 'next'}
303303
end
304304

305+
def test_empty_conditional
306+
source = %q{
307+
- prev_page
308+
li.previous
309+
a href=prev_page Older
310+
- next_page
311+
li.next
312+
a href=next_page Newer}
313+
assert_html'<li class="next"><a href="next">Newer</a></li>', source, scope: {prev_page: '', next_page: 'next'}
314+
end
315+
305316
def test_render_with_yield
306317
source = %q{
307318
div

0 commit comments

Comments
 (0)