bringing back the string.

Symbols are not garbage collected and I don't want to use the large (but cool) HashWithIndifferentAccess.  I could use OpenStruct ala camping but that seems unnecessary.

Long live the string.
This commit is contained in:
Blake Mizerany 2008-03-31 18:48:06 -07:00
parent 1bcd28fa13
commit be5f5270ec
4 changed files with 8 additions and 8 deletions

View File

@ -149,7 +149,7 @@ module Sinatra
@param_keys = [] @param_keys = []
@options = options @options = options
regex = @path.to_s.gsub(PARAM) do regex = @path.to_s.gsub(PARAM) do
@param_keys << $1.intern @param_keys << $1
"(#{URI_CHAR}+)" "(#{URI_CHAR}+)"
end end
@ -586,9 +586,9 @@ module Sinatra
end end
def params def params
@params ||= @route_params.merge(@request.params).symbolize_keys @params = @route_params.merge(@request.params)
end end
def stop(*args) def stop(*args)
throw :halt, args throw :halt, args
end end

View File

@ -18,7 +18,7 @@ context "Sinatra" do
specify "handles events" do specify "handles events" do
get '/:name' do get '/:name' do
'Hello ' + params[:name] 'Hello ' + params["name"]
end end
get_it '/Blake' get_it '/Blake'

View File

@ -42,7 +42,7 @@ context "Looking up a request" do
result.should.not.be.nil result.should.not.be.nil
result.block.should.be block result.block.should.be block
result.params.should.equal :foo => 'bar' result.params.should.equal "foo" => 'bar'
end end
end end
@ -120,7 +120,7 @@ context "Events in an app" do
specify "get access to request, response, and params" do specify "get access to request, response, and params" do
get '/:foo' do get '/:foo' do
params[:foo] + params[:bar] params["foo"] + params["bar"]
end end
get_it '/foo?bar=baz' get_it '/foo?bar=baz'

View File

@ -28,12 +28,12 @@ context "Simple Events" do
specify "takes params in path" do specify "takes params in path" do
result = invoke_simple('/:foo/:bar', '/a/b') result = invoke_simple('/:foo/:bar', '/a/b')
result.should.not.be.nil result.should.not.be.nil
result.params.should.equal :foo => 'a', :bar => 'b' result.params.should.equal "foo" => 'a', "bar" => 'b'
# unscapes # unscapes
result = invoke_simple('/:foo/:bar', '/a/blake%20mizerany') result = invoke_simple('/:foo/:bar', '/a/blake%20mizerany')
result.should.not.be.nil result.should.not.be.nil
result.params.should.equal :foo => 'a', :bar => 'blake mizerany' result.params.should.equal "foo" => 'a', "bar" => 'blake mizerany'
end end
specify "ignores to many /'s" do specify "ignores to many /'s" do