0
0
Fork 0

use URI to get parameters

This commit is contained in:
Gibheer 2012-11-30 14:46:52 +01:00
parent 9cea623595
commit ec446a53b1
3 changed files with 21 additions and 9 deletions

View File

@ -88,9 +88,7 @@ module Zero
# @param query [String] the query string
# @return [Hash] the key/valuie pairs
def parse_string(query)
params = query.split('&')
params.map! {|part| part.split('=') }
Hash[params]
Hash[URI.decode_www_form(query)]
end
end
end

View File

@ -3,17 +3,17 @@ require 'spec_helper'
describe Zero::Request::Parameter, '#payload' do
subject { Zero::Request::Parameter.new(env) }
context "without parameters" do
context 'without parameters' do
let(:env) { EnvGenerator.get('/foo') }
its(:payload) { should == {} }
end
context "with a query string" do
context 'with a query string' do
let(:env) { EnvGenerator.get('/foo?bar=baz') }
its(:payload) { should == {} }
end
context "with a post body" do
context 'with a post body' do
let(:env) do
EnvGenerator.post('/foo', {
:input => 'bar=baz', 'CONTENT_TYPE' => 'multipart/form-data'
@ -21,4 +21,13 @@ describe Zero::Request::Parameter, '#payload' do
end
its(:payload) { should == {'bar' => 'baz'} }
end
context 'with special characters' do
let(:env) do
EnvGenerator.post('/foo', {
:input => 'bar=foo%20bar', 'CONTENT_TYPE' => 'multipart/form-data'
})
end
its(:payload) { should == {'bar' => 'foo bar'} }
end
end

View File

@ -3,18 +3,23 @@ require 'spec_helper'
describe Zero::Request::Parameter, '#query' do
subject { Zero::Request::Parameter.new(env) }
context "without parameters" do
context 'without parameters' do
let(:env) { EnvGenerator.get('/foo') }
its(:query) { should == {} }
end
context "with a query string" do
context 'with a query string' do
let(:env) { EnvGenerator.get('/foo?bar=baz') }
its(:query) { should == {'bar' => 'baz'} }
end
context "with a post body" do
context 'with a post body' do
let(:env) { EnvGenerator.post('/foo', {:input => 'bar=baz'}) }
its(:query) { should == {} }
end
context 'with special characters' do
let(:env) { EnvGenerator.get('/foo?bar=foo%20bar') }
its(:query) { should == {'bar' => 'foo bar'} }
end
end