Skip to content

Conversation

@PaceHeartLater
Copy link

The optimized URL helpers call empty? without checking respond_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 bug

Problem

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 causes NoMethodError exceptions when using objects that don't implement empty? as URL parameters.

What This PR Does

This PR adds a test that demonstrates the bug by:

  • Creating a test object that doesn't implement empty?
  • Attempting to use it as a URL parameter
  • Showing that the current code fails with NoMethodError

The 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 implement empty?.

…pty? The optimized URL helpers call `empty?` without checking `respond_to?(:empty?)` first, causing NoMethodError for objects that don't implement the method. Includes a test that fails before this fix and succeeds after.
@rails-bot rails-bot bot added the actionpack label Jul 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants