-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix invalid if condition parameter #128
Fix invalid if condition parameter #128
Conversation
Thanks for this one! |
@paganotoni , I'm glad I was able to help :) |
I think I found an issue with this PR, it seems it broke the example in here: https://github.com/gobuffalo/plush#full-example
Should return true if the names variable is set. |
I think there is a test for the example in there but this is a different test case, added it here. func Test_Render_If_Value(t *testing.T) {
r := require.New(t)
input := `<%= if (names) { %>hi<%} %>`
ctx := NewContext()
ctx.Set("names", "123")
s, err := Render(input, ctx)
r.NoError(err)
r.Equal("", s)
} |
The provided test should return "hi"? |
I think so, the issue is then |
@paganotoni , it makes sense to accept it. I will push a fix soon to check if |
I was wondering if we shouldn't accept |
I'm thinking we should go back to the concept of truth in plush, from the examples it seems to me that any variable/value set in the context should be considered true except |
Sounds good. I will remove the check from the compiler. However, the parser will still throw an error for these conditions:
Sent a pull request pull#131 |
Fixes issue 115
The new pull requests confirm the validity of the If condition parameter during parsing and compiling. It checks for syntax error and if the evaluated
If condition
is of a typeBool
ornil
During Parsing:
We check if the
expression. Condition
implementsast.Comparable
. If not, then a syntax error is returned. If the type ofexpression. Condition
is of typeast.InflixExpression
then we also check the Left and Right expressions do implementast.Comparable
recursively.During Compilation:
We confirm the evaluated type return of the if condition to be either
bool
ornil
.