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.

routing not recognizing requirements for :format

#2151

This is similar to ticket 2043, which was resolved a few days ago. I have the patch to solve that problem in my source code from a recent downloaded and still have the following problem;-

Use case I've switched from IIS to RoR and changed all my url endings and also file names to be SEO friendly, but Google and hundreds of external links pointing to us are sending me requests with the old file names and old extensions.

Easy solution I define a route which maps every request for a url ending in .htm to an action which works out which new url to redirect the request to. This works in Rails versions up to 2.2.2 but now fails in 2.3.1

Example routes


map.public_view ':id.:format', 
            :controller => 'public_view',
            :action =>'territory_listing',
            :requirements => { :method =>'get',  :format =>/html/i}

map.public_view ':id.:format', # aliasing from old style
            :controller => 'public_view',
            :action =>'redirect_from_old',
            :requirements => { :method =>'get',  :format =>/htm/i} # old style pages ended with htm

My test which now fails is


assert_recognizes({:controller => "public_view",
                     :action =>"redirect_from_old",
                     :format=>'htm',:method=>'get',
                     :id=>'Budget Flights'},
                     "/Budget Flights.htm",{},"/Budget Flights.htm not recognised")

It's picking up the action from the prior route, i.e 'territory_listing' which has requirements :format =>/html/i

In fact I can change /html/i to /htjjjjjml/l and it'll still pick that route. So the routing is not testing requirements properly at least for :format =>/something/

Reported by John Small · March 6th, 2009 @ 02:55 PM

State: stale
Milestone: 2.3.4
Assigned to: josh josh
Importance: none

Activity

  1. CancelProfileIsBroken
    CancelProfileIsBroken

    Here's a test that fails on edge.

    March 6th, 2009 @ 03:52 PM

  2. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from routing error, 2.3-rc1, routes, routing to routing error, 2.3-rc1, bugmash, routes, routing

    August 5th, 2009 @ 02:31 PM

  3. Dan Croak
    Dan Croak

    I couldn't get Mike's patch to apply on 2-3-stable so I've attached a patch with his test (slightly formatted to fit in my text editor).

    I couldn't figure out where to look to make the test pass, but found some contenders:

    http://gist.github.com/164536

    Someone else needs to take it across the goaline. Definitely looks like a bug.

    August 9th, 2009 @ 12:05 AM

  4. Kieran P
    Kieran P

    +1 for Dan Croaks patch for 2-3.

    Mikes patch does not apply to the current version of master. Uploading new one that does.

    August 9th, 2009 @ 02:43 AM

  5. Jeremy Kemper
    Jeremy Kemper
    • Assigned user set to josh
    • State changed from new to open
    • Milestone changed from 2.x to 2.3.4

    August 9th, 2009 @ 03:35 AM

  6. RomKo
    RomKo

    +1 for test patch, verified applies to master.

    I dug around a bit, it seems that the :format requirement drops in RouteBuilder#assign_route_options since there's an optional segment for :format called OptionalFormatSegment.

    August 9th, 2009 @ 07:03 AM

  7. Derander
    Derander

    +1 verified, applies to master.

    I read the test, looks like it is testing the right thing. I'll look into a patch.

    August 10th, 2009 @ 07:44 AM

  8. josh
    josh
    • State changed from open to incomplete

    August 19th, 2009 @ 03:58 PM

  9. josh
    josh
    • State changed from incomplete to stale

    August 31st, 2009 @ 06:57 PM