use URI to get parameters
This commit is contained in:
parent
9cea623595
commit
ec446a53b1
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user