Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Regexp ignore-case option in routes breaks params

#4806

(see attached for an example app with this code)

If you have a blank app with the following controller:

class TestController < ApplicationController
  def index
    render :text => params.inspect
  end
end

and the following in routes.rb:

get "/:foo/:bar" => 'test#index', :foo => /first/i, :bar => /second/

when going to /first/second, the expected response would have both the :foo and :bar components in it, but it actually is the following:

{"action"=>"index", "foo"=>"first", "controller"=>"test"}

The second component somehow gets swallowed. I'm not sure exactly what's going on, so hopefully we can figure this out.

Reported by Andrew Bloomgarden · June 9th, 2010 @ 09:07 AM

State: committed
Milestone: 3.0.2
Assigned to: josh josh
Importance: Low

Activity

  1. Andrew Bloomgarden
    Andrew Bloomgarden
    • Title changed from Two regexp options in routing breaks params to Regexp ignore-case option in routes breaks params

    June 9th, 2010 @ 09:42 AM

  2. DHH
    DHH
    • Milestone cleared.
    • Assigned user set to josh

    June 9th, 2010 @ 05:11 PM

  3. Andrew Bloomgarden
    Andrew Bloomgarden

    Attached is a patch with a couple of failing tests.

    June 9th, 2010 @ 11:20 PM

  4. Andrew Bloomgarden
    Andrew Bloomgarden

    Alright, I believe I've found the issue. Given this in the routing test:

    controller :articles do
      scope '/articles', :name_prefix => 'article' do
        scope :path => '/:title', :title => /[a-z]+/i, :as => :with_title do
          match '/:id', :to => :with_id
        end
      end
    end
    

    the Rack::Mount::Route for article_with_title has named_captures

    {:path_info=>{:title=>0, :id=>2}}
    

    but without the ignore-case flag it has

    {:path_info=>{:title=>0, :id=>1}}
    

    Now to actually fix it…

    June 9th, 2010 @ 11:36 PM

  5. Andrew Bloomgarden
    Andrew Bloomgarden
    • Tag changed from rails3 routes, bug, rails3, regression to rails3 routes, bug, rack-mount, rails3, regression

    Turns out this is a rack-mount issue, so I've attached a failing test case for that.

    June 9th, 2010 @ 11:50 PM

  6. Andrew Bloomgarden
    Andrew Bloomgarden
    • Tag changed from rails3 routes, bug, rack-mount, rails3, regression to rails3 routes, bug, patch, rack-mount, rails3, regression

    And here's a fix. RegexpWithNamedGroups was treating (?i-mx:blah) and the like as captures.

    June 10th, 2010 @ 12:19 AM

  7. Andrew Bloomgarden
    Andrew Bloomgarden

    One last patchfile, this one with an explicit test added for RegexpWithNamedGroups.

    June 10th, 2010 @ 02:13 AM

  8. Andrew Bloomgarden
    Andrew Bloomgarden

    And that makes the ActionDispatch test pass, as expected.

    June 10th, 2010 @ 02:30 AM

  9. José Valim
    José Valim
    • State changed from new to committed

    Closing since it was already applied to Rack-Mount.

    June 23rd, 2010 @ 12:23 PM

  10. Jeremy Kemper
    Jeremy Kemper
    • Milestone set to 3.0.2
    • Importance changed from to Low

    October 15th, 2010 @ 11:01 PM