Skip to content
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

StrictDefaultUndefined ignores undefined variables in filters other than default #62

Closed
hardiksondagar opened this issue Aug 10, 2022 · 4 comments · Fixed by #65
Closed
Labels
bug Something isn't working

Comments

@hardiksondagar
Copy link

The recently introduced StrictDefaultUndefined mode works perfectly with the default filter, but it's ignoring undefined variables in other filters.

from liquid import Environment
from liquid import StrictDefaultUndefined

env = Environment(undefined=StrictDefaultUndefined)
template = env.from_string('Hello {{ username | floor }}')
print(template.render())

Hello 0
@jg-rp jg-rp added the bug Something isn't working label Aug 10, 2022
jg-rp added a commit that referenced this issue Aug 10, 2022
@jg-rp
Copy link
Owner

jg-rp commented Aug 10, 2022

Hi @hardiksondagar,

Thank you for letting me know. StrictDefaultUndefined has been fixed in version 1.4.1, and I've been more thorough with the test cases this time.

@hardiksondagar
Copy link
Author

Thanks a lot, @jg-rp for quick fixes. Let me know how I can start contributing to the project and maybe you can point me to the contribution guide if it's available.

@jg-rp
Copy link
Owner

jg-rp commented Aug 13, 2022

Your contributions would be most welcome. I've started some contributing guidelines and done some workflow maintenance in anticipation.

Most of my own efforts will be focused on Liquid Babel and getting feature parity between Python Liquid and LiquidScript.

@hardiksondagar
Copy link
Author

Hi @jg-rp, the default filter with v1.4.1 is ignoring zero value.

from liquid import Environment
from liquid import StrictDefaultUndefined

env = Environment(undefined=StrictDefaultUndefined)
template = env.from_string('My value is {% assign var_x = 0 %} {{ var_x | default: "hello"}}')
print(template.render())

# with allow_false parameter
template = env.from_string('My value is {% assign var_x = 0 %} {{ var_x | default: "hello", allow_false: true}}')
print(template.render())

--
My value is hello
My value is hello

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants