Fix some internal errors in filters from invalid input.#1476
Merged
dylanahsmith merged 1 commit intomasterfrom Feb 24, 2022
Merged
Fix some internal errors in filters from invalid input.#1476dylanahsmith merged 1 commit intomasterfrom
dylanahsmith merged 1 commit intomasterfrom
Conversation
macournoyer
approved these changes
Sep 17, 2021
| nil | ||
| end | ||
| end | ||
| (@filters.public_methods - Object.public_methods).each do |method| |
Contributor
There was a problem hiding this comment.
I think you could use public_methods(false) to only get the methods on the receiver:
Suggested change
| (@filters.public_methods - Object.public_methods).each do |method| | |
| @filters.public_methods(false).each do |method| |
Contributor
Author
There was a problem hiding this comment.
@filters.public_methods(false) would return [] since @filters is an instance of a class that includes the StandardFilters module. However, we could use StandardFilters.public_instance_methods(false) to get those methods directly. I tested (@filters.public_methods - Object.public_instance_methods) == StandardFilters.public_instance_methods(false) locally and it returns true
These fixes came from improving the corresponding test, so these might not actually be causing problems in practice.
37850fc to
0912f68
Compare
mtasaka
added a commit
to mtasaka/liquid
that referenced
this pull request
Nov 26, 2023
Ruby returns 0 (not nil) for nil <=> nil, i.e. nil and nil are judged as equal for comparison, and so returns nil_safe_compare . ref: Shopify#1476 To make the behavior of nil_safe_casecmp consistent with nil_safe_compare , change nil_safe_casecmp so that comparison between nil <=> nil return 0 (equal). Also change testsuite to reflect this change. Fixes Shopify#1759 .
mtasaka
added a commit
to mtasaka/liquid
that referenced
this pull request
Dec 15, 2023
Ruby returns 0 (not nil) for nil <=> nil, i.e. nil and nil are judged as equal for comparison, and so returns nil_safe_compare . ref: Shopify#1476 To make the behavior of nil_safe_casecmp consistent with nil_safe_compare , change nil_safe_casecmp so that comparison between nil <=> nil return 0 (equal). Also change testsuite to reflect this change. Fixes Shopify#1759 .
andrykonchin
pushed a commit
to andrykonchin/liquid
that referenced
this pull request
Feb 24, 2025
Ruby returns 0 (not nil) for nil <=> nil, i.e. nil and nil are judged as equal for comparison, and so returns nil_safe_compare . ref: Shopify#1476 To make the behavior of nil_safe_casecmp consistent with nil_safe_compare , change nil_safe_casecmp so that comparison between nil <=> nil return 0 (equal). Also change testsuite to reflect this change. Fixes Shopify#1759 .
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
While reviewing #1422 I noticed that StandardFilters#test_all_filters_never_raise_non_liquid_exception was doing a lot of redundant work and started to change it to make it more scalable and general. In the process, I noticed that it also wasn't passing in a default argument, which prevented it from finding some code paths that could result in internal errors.
Solution
I used Array#repeated_permutation in StandardFilters#test_all_filters_never_raise_non_liquid_exception so it would test permutations in proportion to the arity of the filter. If the filter method takes optional arguments, then pass in an optional argument in addition to the required arguments.
This uncovered a few errors:
ary.first.respond_to?(:[])checks which assumed the array had elements of a homogenous type, which could result in an internal error if the first argument responded to[]but a following one didn't. I added arescue NoMethodErrorto handle these errors.nilto explicitly raise a liquid error.Note that I haven't actually checked if these internal errors are happening in practice.