Skip to content

Commit 37a5409

Browse files
authored
fix interpreting optional with 0 value as true in checks (#281)
1 parent 2e5e2b5 commit 37a5409

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/filters.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ InternalValue SequenceAccessor::Filter(const InternalValue& baseVal, RenderConte
486486
switch (m_mode)
487487
{
488488
case FirstItemMode:
489-
if (listSize)
489+
if (listSize && *listSize > 0)
490490
result = ProtectedValue( list.GetValueByIndex(0) );
491491
else
492492
{
@@ -496,7 +496,7 @@ InternalValue SequenceAccessor::Filter(const InternalValue& baseVal, RenderConte
496496
}
497497
break;
498498
case LastItemMode:
499-
if (listSize)
499+
if (listSize && *listSize > 0)
500500
result = ProtectedValue(list.GetValueByIndex(listSize.value() - 1));
501501
else
502502
{
@@ -507,7 +507,7 @@ InternalValue SequenceAccessor::Filter(const InternalValue& baseVal, RenderConte
507507
}
508508
break;
509509
case LengthMode:
510-
if (listSize)
510+
if (listSize && *listSize > 0)
511511
result = static_cast<int64_t>(listSize.value());
512512
else
513513
result = static_cast<int64_t>(std::distance(list.begin(), list.end()));
@@ -516,7 +516,7 @@ InternalValue SequenceAccessor::Filter(const InternalValue& baseVal, RenderConte
516516
{
517517
std::random_device rd;
518518
std::mt19937 gen(rd());
519-
if (listSize)
519+
if (listSize && *listSize > 0)
520520
{
521521
std::uniform_int_distribution<> dis(0, static_cast<int>(listSize.value()) - 1);
522522
result = ProtectedValue(list.GetValueByIndex(dis(gen)));

0 commit comments

Comments
 (0)