harttle / liquidjs

A simple, expressive, safe and Shopify compatible template engine in pure JavaScript.
https://liquidjs.com
MIT License
1.5k stars 237 forks source link

Enhance `isComparable` function for full Comparable interface implementation #700

Closed GuillermoCasalCaro closed 3 months ago

GuillermoCasalCaro commented 3 months ago

Hello, this is my first created issue, if there is something wrong just tell me!

The current implementation of the isComparable function only checks if the equals method is present on the object. This is leading me to issues when I'm using a custom Drop class that casually also has an implementation of equals, but I don't want to make it an implementation of the Comparable interface.

When I use the operators <, >, <=, and >= the class is detected as an implementation of Comparable and tries to execute the related functions. This happens in the operator code.

Proposed Solution

Enhance the isComparable function to check for the complete implementation of the Comparable interface, ensuring that the methods equals, gt, geq, lt, and leq are present on the object.

I made a fork and a PR for this. I will link it right now.

Benefits

This will ensure that objects are properly evaluated and that they will use the proper comparison functions, improving the robustness of the template evaluation for the operators <, >, <=, and >=.

Please let me know if this enhancement is acceptable or if there are any changes or additional considerations I should take into account.

github-actions[bot] commented 3 months ago

:tada: This issue has been resolved in version 10.13.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: