Hi all, I seem to have a problem. I attached a test case which I can't make pass. The route was extracted verbatim from an existing application. If I rollback in time to r4393, the tests pass. The route is: map.game_instructions 'game/:game/instructions', :controller => 'games', :action => 'instructions', :requirements => {:game => /\A[-\w \+%]+\Z/i} That is one of many routes I test. The only route test I can make pass is if I remove the requirements. In the tests, you'll also see I have much less stringent requirements for the game parameter: /^.*$/ is one of them, and that fails too. Can anyone shed some light on this ? Thanks ! -- François Beausoleil http://blog.teksol.info/ _______________________________________________ Rails-core mailing list Rails-core@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-core
I lost even the most basic automatic routing support for the module/:controller/:action/:id URL format going from 1.1.2 to 1.1.3. I had to lock all my apps back to 1.1.2. Is my issue the same issue as Francois? Actual data but .com names have been changed to protect the innocent: --- route.rb ActionController::Routing::Routes.draw do |map| map.connect '''', :controller => "public" map.connect '':controller/:action/:id'' end --- example URL that now fails with unknown route under 1.1.3 http://www.client.com/admin/user/edit/1 --- expected route Admin::UserController#edit with :id = 1 Michael Genereux SimianCodex Francois Beausoleil wrote:> Hi all, > > I seem to have a problem. I attached a test case which I can''t make > pass. The route was extracted verbatim from an existing application. > If I rollback in time to r4393, the tests pass. > > The route is: > map.game_instructions ''game/:game/instructions'', :controller => ''games'', > :action => ''instructions'', :requirements => {:game => /\A[-\w > \+%]+\Z/i} > > That is one of many routes I test. The only route test I can make > pass is if I remove the requirements. In the tests, you''ll also see I > have much less stringent requirements for the game parameter: /^.*$/ > is one of them, and that fails too. > > Can anyone shed some light on this ? > > Thanks ! > ------------------------------------------------------------------------ > > _______________________________________________ > Rails-core mailing list > Rails-core@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-core >
Francois, I suspect the problem is that the :game regex has \A and \Z in it. Because the new routes put that verbatim into the larger route regex, the match will fail. (Ditto for the /^.*$/ regex, with the ^ and $ anchors.) I *think* (Nicholas, correct me if I''m wrong) that you can just take the \A and \Z out of the regex and all will be well. Can you give that a spin and see what happens? - Jamis On Jun 28, 2006, at 2:14 AM, Francois Beausoleil wrote:> Hi all, > > I seem to have a problem. I attached a test case which I can''t make > pass. The route was extracted verbatim from an existing application. > If I rollback in time to r4393, the tests pass. > > The route is: > map.game_instructions ''game/:game/instructions'', :controller => > ''games'', > :action => ''instructions'', :requirements => {:game => /\A[-\w \+ > %]+\Z/i} > > That is one of many routes I test. The only route test I can make > pass is if I remove the requirements. In the tests, you''ll also see I > have much less stringent requirements for the game parameter: /^.*$/ > is one of them, and that fails too. > > Can anyone shed some light on this ? > > Thanks ! > -- > François Beausoleil > http://blog.teksol.info/ > <routing-test.patch> > _______________________________________________ > Rails-core mailing list > Rails-core@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-core
2006/6/28, Jamis Buck <jamis@37signals.com>:> Francois, > > I suspect the problem is that the :game regex has \A and \Z in it. > Because the new routes put that verbatim into the larger route regex, > the match will fail. (Ditto for the /^.*$/ regex, with the ^ and $ > anchors.) I *think* (Nicholas, correct me if I'm wrong) that you can > just take the \A and \Z out of the regex and all will be well. Can > you give that a spin and see what happens?By the way, isn't \A \z better than \A \Z ? -- Jean-François. -- À la renverse. _______________________________________________ Rails-core mailing list Rails-core@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-core
Ah ha ! 2006/6/28, Jamis Buck <jamis@37signals.com>:> I suspect the problem is that the :game regex has \A and \Z in it. > Because the new routes put that verbatim into the larger route regex, > the match will fail. (Ditto for the /^.*$/ regex, with the ^ and $ > anchors.) I *think* (Nicholas, correct me if I'm wrong) that you can > just take the \A and \Z out of the regex and all will be well. Can > you give that a spin and see what happens?Bingo. Now that this is resolved, I'd like to prevent the same problem for other people. So, I need to patch the routing module to complain if a requirement is a regexp, and the regexp contains ^, $, \A or \Z. Just a little pointer on where I should start would be appreciated. I'll take it from there. When I say complain, I really mean an exception. Thanks ! -- François Beausoleil http://blog.teksol.info/ _______________________________________________ Rails-core mailing list Rails-core@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-core
On 6/28/06, Francois Beausoleil <francois.beausoleil@gmail.com> wrote:> > Hi all, > > The route is: > map.game_instructions ''game/:game/instructions'', :controller => ''games'', > :action => ''instructions'', :requirements => {:game => /\A[-\w > \+%]+\Z/i} >Placing ^, \A, \Z, and $ inside regexp captures for requirements is not required, and should not be allowed. When you say :game => /[a-z]+/ routes should interpret this as \A[a-z]+\Z when matching against a single value. Keep in mind that the supplied regexp must work inside of a single regexp for the whole path. So using any of the aforementioned controls will obviously cause this to fail. If you come across a case where removing your control characters causes regexps to match input it should not, please let me know. Perhaps we should add an informative error message for this case. Feel free to weight in if you think so. (Or better yet, send a diff + unit test.) Thanks, Nicholas Seckar _______________________________________________ Rails-core mailing list Rails-core@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-core
Hello Jean-François, 2006/6/28, Jean-François <jf.web3@gmail.com>:> By the way, isn't \A \z better than \A \Z ?Actually, you might be right, except in this case it doesn't matter. From "Programming Ruby" 2nd edition, p. 70, section Anchors: """The sequence \A matches the beginning of a string, and \z and \Z match the end of a string. (Actually, \Z matches the end of a string /unless/ the string ends with a \n, in which case it matches just before the \n.)""" Thanks for bringing this up. I wasn't aware of \z. Bye ! -- François Beausoleil http://blog.teksol.info/ _______________________________________________ Rails-core mailing list Rails-core@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-core
Hello Nicholas ! 2006/6/28, Nicholas Seckar <nseckar@gmail.com>:> Perhaps we should add an informative error message for this case. Feel free > to weight in if you think so. (Or better yet, send a diff + unit test.)I will, I only need a pointer on where I should start searching. With that, I'll patch, with tests, of course. Thanks ! -- François Beausoleil http://blog.teksol.info/ _______________________________________________ Rails-core mailing list Rails-core@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-core
On 6/28/06, Francois Beausoleil <francois.beausoleil@gmail.com> wrote:> > Hello Nicholas ! > > 2006/6/28, Nicholas Seckar <nseckar@gmail.com>: > > Perhaps we should add an informative error message for this case. Feel > free > > to weight in if you think so. (Or better yet, send a diff + unit test.) > > I will, I only need a pointer on where I should start searching. With > that, I''ll patch, with tests, of course.Awesome. There are two places Regexp''s appear. They are attached to segments in the path as segment.regexp (See DynamicSegment.) and they also appear on the route''s requirements hash (route.requirements.) However they both pass thru RouteBuilder during route construction. Adding the check there may be the key to staying DRY. Good luck! (Feel free to email me directly if you have more questions.) Cheers, Nicholas _______________________________________________ Rails-core mailing list Rails-core@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-core
Hi ! 2006/6/28, Nicholas Seckar <nseckar@gmail.com>:> Awesome. > > There are two places Regexp's appear. They are attached to segments in the > path as segment.regexp (See DynamicSegment.) and they also appear on the > route's requirements hash (route.requirements.) > > However they both pass thru RouteBuilder during route construction. Adding > the check there may be the key to staying DRY.See ticket #5674: http://dev.rubyonrails.org/ticket/5674 I followed your suggestion, Nicholas, to add the code to RouteBuilder. We also sport a new RuntimeError class: ActionController::Routing::SyntaxError. NOTE: I had to change a previously working test to pass again. I wonder why the test didn't expose the same bug I had ? Bye ! -- François Beausoleil http://blog.teksol.info/ _______________________________________________ Rails-core mailing list Rails-core@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-core