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
7 changes: 7 additions & 0 deletions parser_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ func (expr *relationalExpression) Evaluate(ctx *ExecutionContext) (*Value, *Erro
case "!=", "<>":
return AsValue(!v1.EqualValueTo(v2)), nil
case "in":
val, ok := expr.expr1.(*simpleExpression)
if ok && val.negate {
t1, err := val.term1.Evaluate(ctx)
if err == nil {
Copy link
Owner

@flosch flosch Dec 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if err != nil? Shouldn't this be handled somehow?

return AsValue(!v2.Contains(t1)), nil
}
}
return AsValue(v2.Contains(v1)), nil
default:
return nil, ctx.Error(fmt.Sprintf("unimplemented: %s", expr.opToken.Val), expr.opToken)
Expand Down
2 changes: 2 additions & 0 deletions template_tests/if.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
{% if !simple.uint %}false{% else %}!simple.uint{% endif %}
{% if !simple.float %}false{% else %}!simple.float{% endif %}
{% if "Text" in complex.post %}text field in complex.post{% endif %}
Hello string {% if not "Hello" in complex.post.Text %}is not{% else %}is{% endif %} in complex.post.Text
World string {% if not "World" in complex.post.Text %}is not{% else %}is{% endif %} in complex.post.Text
{% if 5 in simple.intmap %}5 in simple.intmap{% endif %}
{% if !0.0 %}!0.0{% endif %}
{% if !0 %}!0{% endif %}
Expand Down
2 changes: 2 additions & 0 deletions template_tests/if.tpl.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ float != 0.0
!simple.uint
!simple.float
text field in complex.post
Hello string is in complex.post.Text
World string is not in complex.post.Text
5 in simple.intmap
!0.0
!0
Expand Down