You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Open file: pongo2/template_tests/if.tpl and add two conditions after this line: {% 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
In pongo2_template_test.go the "complex.post.Text" = <h2>Hello!</h2><p>Welcome...
So, we are expecting the "World" does not exist in the string we should get two different results, However result are:
Hello string is in complex.post.Text
World string is in complex.post.Text
The text was updated successfully, but these errors were encountered:
Open the file parser_expression.go, the problem in "result = result.Negate()". It may work for Boolean types but definitely not for String.
func (expr *simpleExpression) Evaluate(ctx *ExecutionContext) (*Value, *Error) {
t1, err := expr.term1.Evaluate(ctx)
if err != nil {
return nil, err
}
result := t1
if expr.negate {
result = result.Negate()
}
Such as common function for backward compatibility I implemented the fix in that function:
"func (expr *relationalExpression) Evaluate(ctx *ExecutionContext) (*Value, *Error) {"
case "in":
val, ok := expr.expr1.(*simpleExpression)
if ok && val.negate {
t1, err := val.term1.Evaluate(ctx)
if err == nil {
return AsValue(!v2.Contains(t1)), nil
}
}
return AsValue(v2.Contains(v1)), nil
Open file: pongo2/template_tests/if.tpl and add two conditions after this line:
{% 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
In pongo2_template_test.go the "complex.post.Text" =
<h2>Hello!</h2><p>Welcome...
So, we are expecting the "World" does not exist in the string we should get two different results, However result are:
The text was updated successfully, but these errors were encountered: