This project is archived and is in readonly mode.
routing not recognizing requirements for :format
Reported by John Small | March 6th, 2009 @ 02:55 PM | in 2.3.4
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/
Comments and changes to this ticket
-
CancelProfileIsBroken August 5th, 2009 @ 02:31 PM
- Tag changed from routing error, 2.3-rc1, routes, routing to routing error, 2.3-rc1, bugmash, routes, routing
-
Dan Croak August 9th, 2009 @ 12:05 AM
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:
Someone else needs to take it across the goaline. Definitely looks like a bug.
-
Kieran P August 9th, 2009 @ 02:43 AM
+1 for Dan Croaks patch for 2-3.
Mikes patch does not apply to the current version of master. Uploading new one that does.
-
Jeremy Kemper August 9th, 2009 @ 03:35 AM
- Assigned user set to josh
- State changed from new to open
- Milestone changed from 2.x to 2.3.4
-
RomKo August 9th, 2009 @ 07:03 AM
+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.
-
Derander August 10th, 2009 @ 07:44 AM
+1 verified, applies to master.
I read the test, looks like it is testing the right thing. I'll look into a patch.
-
josh August 19th, 2009 @ 03:58 PM
- State changed from open to incomplete
-
josh August 31st, 2009 @ 06:57 PM
- State changed from incomplete to stale
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 2772 Routing: 2.3 provides no way to require a :format Please follow up on #2151
- 2772 Routing: 2.3 provides no way to require a :format Related: #2151 which covers the :requirements case.