Skip to content

Commit 49b6520

Browse files
authored
fix interpreting optional with 0 value as true in checks
1 parent 2053cfa commit 49b6520

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/filters.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ InternalValue SequenceAccessor::Filter(const InternalValue& baseVal, RenderConte
487487
switch (m_mode)
488488
{
489489
case FirstItemMode:
490-
if (listSize)
490+
if (listSize && *listSize > 0)
491491
result = ProtectedValue( list.GetValueByIndex(0) );
492492
else
493493
{
@@ -497,7 +497,7 @@ InternalValue SequenceAccessor::Filter(const InternalValue& baseVal, RenderConte
497497
}
498498
break;
499499
case LastItemMode:
500-
if (listSize)
500+
if (listSize && *listSize > 0)
501501
result = ProtectedValue(list.GetValueByIndex(listSize.value() - 1));
502502
else
503503
{
@@ -508,7 +508,7 @@ InternalValue SequenceAccessor::Filter(const InternalValue& baseVal, RenderConte
508508
}
509509
break;
510510
case LengthMode:
511-
if (listSize)
511+
if (listSize && *listSize > 0)
512512
result = static_cast<int64_t>(listSize.value());
513513
else
514514
result = static_cast<int64_t>(std::distance(list.begin(), list.end()));
@@ -517,7 +517,7 @@ InternalValue SequenceAccessor::Filter(const InternalValue& baseVal, RenderConte
517517
{
518518
std::random_device rd;
519519
std::mt19937 gen(rd());
520-
if (listSize)
520+
if (listSize && *listSize > 0)
521521
{
522522
std::uniform_int_distribution<> dis(0, static_cast<int>(listSize.value()) - 1);
523523
result = ProtectedValue(list.GetValueByIndex(dis(gen)));

0 commit comments

Comments
 (0)