Skip to content

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

Merged
danog merged 1 commit into
osteele:mainfrom
jamslinger:division-by-zero
Oct 18, 2024
Merged

Don't panic in filter divided_by on division by zero#97
danog merged 1 commit into
osteele:mainfrom
jamslinger:division-by-zero

Conversation

@jamslinger

@jamslinger jamslinger commented Oct 18, 2024

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

fixes #96

@danog

danog commented Oct 18, 2024

Copy link
Copy Markdown
Collaborator

Please implement this by actually checking the value of the denominator

@jamslinger

Copy link
Copy Markdown
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

danog commented Oct 18, 2024

Copy link
Copy Markdown
Collaborator

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

@danog
danog merged commit 71b8fa2 into osteele:main Oct 18, 2024
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