Skip to content

Commit

Permalink
fix(Handlebars): "or" helper returns first truthy value
Browse files Browse the repository at this point in the history
  • Loading branch information
alandefreitas committed Nov 21, 2024
1 parent 29f4d4f commit f9e7af4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion include/mrdocs/Support/Handlebars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ and_fn(dom::Array const& args);
* The "or" helper returns true if any of the values are truthy.
*/
MRDOCS_DECL
bool
dom::Value
or_fn(dom::Array const& args);

/** "eq" helper function
Expand Down
12 changes: 8 additions & 4 deletions src/lib/Support/Handlebars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3934,15 +3934,19 @@ and_fn(dom::Array const& args)
return true;
}

bool
or_fn(dom::Array const& args) {
dom::Value
or_fn(dom::Array const& args)
{
std::size_t const n = args.size();
if (n == 0) return false;
if (n == 0)
{
return false;
}
for (std::size_t i = 0; i < n - 1; ++i)
{
if (args.get(i))
{
return true;
return args.get(i);
}
}
return false;
Expand Down

0 comments on commit f9e7af4

Please sign in to comment.