1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

Allow dot in named param capture [#153]

This commit is contained in:
Ryan Tomayko 2009-02-17 09:32:52 -08:00
parent d212de6abf
commit a2f5803ec6
2 changed files with 27 additions and 1 deletions

View file

@ -682,7 +682,7 @@ module Sinatra
Regexp.escape(match)
else
keys << $2[1..-1]
"([^/?&#\.]+)"
"([^/?&#]+)"
end
end
[/^#{pattern}$/, keys]

View file

@ -139,6 +139,32 @@ describe "Routing" do
assert ok?
end
it "matches a dot ('.') as part of a named param" do
mock_app {
get '/:foo/:bar' do
params[:foo]
end
}
get '/user@example.com/name'
assert_equal 200, response.status
assert_equal 'user@example.com', body
end
it "matches a literal dot ('.') outside of named params" do
mock_app {
get '/:file.:ext' do
assert_equal 'pony', params[:file]
assert_equal 'jpg', params[:ext]
'right on'
end
}
get '/pony.jpg'
assert_equal 200, response.status
assert_equal 'right on', body
end
it "literally matches . in paths" do
route_def '/test.bar'