Skip to content
This repository has been archived by the owner on Sep 13, 2017. It is now read-only.

Route params don't seem to allow periods in values #7

Closed
rmm5t opened this issue Dec 21, 2011 · 7 comments
Closed

Route params don't seem to allow periods in values #7

rmm5t opened this issue Dec 21, 2011 · 7 comments

Comments

@rmm5t
Copy link

rmm5t commented Dec 21, 2011

Update: This issue has evolved into something different than what was originally suspected as the problem. Read this comment for the actual issue


I've only given this a very brief look, but after upgrading to Rails 3.2.0.rc1, one of our custom routes failed to match certain paths that we expected them to match. It seems that when a route parameter's value contains periods, the match no longer succeeds.

I haven't spent any time grokking the journey codebase yet; however here's a test that I got to fail, but that I would have expected to pass.

# in test/nfa/test_simulator.rb
def test_simulate_periods
  sim = simulator_for ['/whois/:domain']
  assert_match sim, '/whois/example'
  assert_match sim, '/whois/example.com'
  assert_match sim, '/whois/www.example.com'
  refute_match sim, '/whois/'
end
@tenderlove
Copy link
Member

In you rails app, when you run rake routes, is /whois/:domain listed? Or is it /whois/:domain(.:format)? Also, does the entire domain name come in as params[:domain]?

@tenderlove
Copy link
Member

Also, can you provide me with the line that you're using in your rails routes.rb file? Thanks!

@rmm5t
Copy link
Author

rmm5t commented Dec 21, 2011

Well, the rails app where I ran into this problem had a much more complicated route (extra contraints and what not), but I just spun up a dummy Rails app to demonstrate the specific example presented above.

Route in routes.rb:

match "whois/:domain" => "whois#show", via: :get, format: false

rake routes:

$ rake routes
 GET /whois/:domain whois#show

💚 Accessing /whois/example works as expected and "example" comes in for params[:domain]

💔 Accessing /whois/example.com throws a RoutingError (No route matches [GET] "/whois/example.com")


Also, if I remove the format: false from the route:

$ rake routes
 GET /whois/:domain(.:format) whois#show

💚 Accessing /whois/example works as expected and "example" comes in for params[:domain]

💛 Accessing /whois/example.com passes "example" for params[:domain] and "com" for params[:format]. This actually might be the expected behavior, but I believe Rails 3.1 behaved differently (haven't tested that yet).

💔 Accessing /whois/www.example.com throws a RoutingError (No route matches [GET] "/whois/www.example.com")

@tenderlove
Copy link
Member

Can you test this with Rails 3.1? I put together a test case, both 3-2-stable and 3-1-stable behaved the same, and I want to make sure we're testing the same thing.

Also, I ❤️ the hearts!!

@rmm5t
Copy link
Author

rmm5t commented Dec 21, 2011

I just tried Rails 3.1 and you're right, my basic example above isn't enough to show the backwards incompatibility I was seeing. It's necessary to have two overlapping routes where the preceding one has a contraint to take care of any ambiguity. I guess I still didn't expect to see the behavior above, but nonetheless, let's try this again:


Rails 3.1.3

match "whois/:domain" => "whois#show", via: :get, format: false, constraints: { domain: /\w+\.[\w\.]+/ }
match "whois/:id" => "whois#show", via: :get
$ rake routes
 GET /whois/:domain       {:domain=>/\w+\.[\w\.]+/, :controller=>"whois", :action=>"show"}
 GET /whois/:id(.:format) {:controller=>"whois", :action=>"show"}

💚 Accessing /whois/example.com matches first route and assigns "example.com" to params[:domain]

💚 Accessing /whois/www.example.com matches first route and assigns "www.example.com" to params[:domain]

💚 Accessing /whois/123 matches second route and assigns "123" to params[:id]


Rails 3.2.0.rc1

match "whois/:domain" => "whois#show", via: :get, format: false, constraints: { domain: /\w+\.[\w\.]+/ }
match "whois/:id" => "whois#show", via: :get
$ rake routes
 GET /whois/:domain       whois#show {:domain=>/\w+\.[\w\.]+/}
 GET /whois/:id(.:format) whois#show

💔 Accessing /whois/example.com matches second route and assigns "example" to params[:id] and "com" to params[:format]. Even though there is ambiguity between the two routes with this path, I expected the first route to take precedence.

💚 Accessing /whois/www.example.com matches first route and assigns "www.example.com" to params[:domain]

💚 Accessing /whois/123 matches second route and assigns "123" to params[:id]


(Thanks for patiently walking through this with me.)

Also, since this issue has sprawled out from its original intention, I'm happy to post this issue somewhere else if you feel it belongs in the Rails issue tracker instead. Let me know. Thanks.

@tenderlove
Copy link
Member

No problem! I think this is an issue with Journey, so no need to change trackers. I think I know where this is broken, but I need to sleep tonight, so I'll fix tomorrow. Thanks for reporting this!

@rmm5t
Copy link
Author

rmm5t commented Dec 21, 2011

Thanks again Aaron! I just got a chance to test this and it works great. 💚

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants