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

Don't panic in filter divided_by on division by zero #97

Merged
merged 1 commit into from
Oct 18, 2024

Conversation

jamslinger
Copy link
Contributor

@jamslinger jamslinger commented Oct 18, 2024

Checklist

  • I have read the contribution guidelines.
  • make test passes.
  • make lint passes.
  • New and changed code is covered by tests.
  • Performance improvements include benchmarks.
  • Changes match the documented (not just the implemented) behavior of Shopify.

@jamslinger
Copy link
Contributor Author

fixes #96

@danog
Copy link
Collaborator

danog commented Oct 18, 2024

Please implement this by actually checking the value of the denominator

@jamslinger
Copy link
Contributor Author

Please implement this by actually checking the value of the denominator

Yes that makes sense.

  • Also found and fixed another bug where type assertion was used on potentially incompatible types, e.g.:
case int, int16, int32, int64: // any non-int type would cause `q.(int)` to panic. 
			return int(a) / q.(int)
  • Also extended the possible divisor types with uintX types that are convertible into int64.
  • Also return an error on any invalid divisor type, this matches the behavior of Shopify liquid that returns an error when e.g. trying something like {{ 40 | divided_by: 's' }}. However, I'd like to hear your opinion on this because it might affect existing code.

@danog
Copy link
Collaborator

danog commented Oct 18, 2024

Thanks, looks all good, especially since it matches shopify behavior.

@danog danog merged commit 71b8fa2 into osteele:main Oct 18, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants