Robustify routing parameters against objects that don't respond to empty? #55403
+35 −1
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.
The optimized URL helpers call
empty?without checkingrespond_to?(:empty?)first, causing NoMethodError for objects that don't implement the method.Includes a test that fails before this fix and succeeds after.
Fix routing parameter
empty?method bugProblem
The Rails routing system's optimized URL helpers have a bug where they call
empty?on parameter objects without first checking if the object responds to that method. This causesNoMethodErrorexceptions when using objects that don't implementempty?as URL parameters.What This PR Does
This PR adds a test that demonstrates the bug by:
empty?NoMethodErrorThe test fails before this fix and succeeds after.
Impact
This bug affects any application using custom objects as URL parameters where those objects don't implement
empty?. The fix is backward compatible and doesn't change behavior for objects that do implementempty?.