summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/uri/decode_www_form_18_spec.rb44
1 files changed, 23 insertions, 21 deletions
diff --git a/spec/unit/uri/decode_www_form_18_spec.rb b/spec/unit/uri/decode_www_form_18_spec.rb
index 3a36cc0..21e1b7c 100644
--- a/spec/unit/uri/decode_www_form_18_spec.rb
+++ b/spec/unit/uri/decode_www_form_18_spec.rb
@@ -2,41 +2,41 @@
require 'spec_helper'
-describe URI, '#parse_query_string' do
+describe URI, '#decode_www_form_18' do
it 'seperates parameter into an array' do
- result = URI::parse_query_string("foo=bar&bar=foo")
+ result = URI::decode_www_form_18("foo=bar&bar=foo")
result.should eq([['foo', 'bar'], ['bar', 'foo']])
end
it 'can handle more than two equal parameter names' do
- result = URI::parse_query_string("foo=bar1&foo=bar2")
+ result = URI::decode_www_form_18("foo=bar1&foo=bar2")
result.should eq([['foo', 'bar1'], ['foo', 'bar2']])
end
it 'can handle whitespaces in query string' do
- result = URI::parse_query_string("foo=bar&bar=bar%20foo")
+ result = URI::decode_www_form_18("foo=bar&bar=bar%20foo")
result.should eq([['foo', 'bar'], ['bar', 'bar foo']])
end
it 'accepts semi-colons as seperators' do
- result = URI::parse_query_string("foo=bar;bar=foo")
+ result = URI::decode_www_form_18("foo=bar;bar=foo")
result.should eq([['foo', 'bar'], ['bar', 'foo']])
end
it 'seperates & and ; mixed queries properly' do
- result = URI::parse_query_string("foo=bar&bar=foo;baz=foo")
+ result = URI::decode_www_form_18("foo=bar&bar=foo;baz=foo")
result.should eq([['foo', 'bar'], ['bar', 'foo'], ['baz', 'foo']])
end
it 'does not accept only a normal string as query string' do
expect{
- result = URI::parse_query_string("foo")
+ result = URI::decode_www_form_18("foo")
# does not work, probably should?
#result.should eq([['foo', '']])
@@ -47,76 +47,78 @@ describe URI, '#parse_query_string' do
end
it 'accepts empty values' do
- result = URI::parse_query_string("foo=bar&bar=&baz=foo")
+ result = URI::decode_www_form_18("foo=bar&bar=&baz=foo")
result.should eq([['foo', 'bar'], ['bar', ''], ['baz', 'foo']])
end
it 'understands plus as whitespace' do
- result = URI::parse_query_string("foo=bar&bar=bar+foo")
+ result = URI::decode_www_form_18("foo=bar&bar=bar+foo")
result.should eq([['foo', 'bar'], ['bar', 'bar foo']])
end
it 'does not accept whitespaces in query string' do
- result = URI::parse_query_string("foo=bar&bar=bar foo&baz=foo")
+ result = URI::decode_www_form_18("foo=bar&bar=bar foo&baz=foo")
# Works, it probably shouldn't?
result.should eq([['foo', 'bar'], ['bar', 'bar foo'], ['baz', 'foo']])
end
it 'can handle non ascii letters in query string' do
- result = URI::parse_query_string("foo=bär&bar=föö")
+ result = URI::decode_www_form_18("foo=bär&bar=föö")
# Works, but it maybe shouldn't?
result.should eq([['foo', 'bär'], ['bar', 'föö']])
end
it 'can handle escaped non ascii letters in query string' do
- result = URI::parse_query_string("foo=b%C3%A4r&bar=f%C3%B6%C3%B6")
+ result = URI::decode_www_form_18("foo=b%C3%A4r&bar=f%C3%B6%C3%B6")
result.should eq([['foo', 'bär'], ['bar', 'föö']])
end
it 'accepts - in query string' do
- result = URI::parse_query_string("foo-bar=bar&bar=foo-bar")
+ result = URI::decode_www_form_18("foo-bar=bar&bar=foo-bar")
+
+ puts (URI::decode_www_form_18("foo-bar=bar&bar=foo-bar") == [['foo-bar', 'bar'], ['bar', 'foo-bar']]).inspect
result.should eq([['foo-bar', 'bar'], ['bar', 'foo-bar']])
end
it 'accepts . in query string' do
- result = URI::parse_query_string("foo.bar=bar&bar=foo.bar")
+ result = URI::decode_www_form_18("foo.bar=bar&bar=foo.bar")
result.should eq([['foo.bar', 'bar'], ['bar', 'foo.bar']])
end
it 'accepts ~ in query string' do
- result = URI::parse_query_string("foo~bar=bar&bar=foo~bar")
+ result = URI::decode_www_form_18("foo~bar=bar&bar=foo~bar")
result.should eq([['foo~bar', 'bar'], ['bar', 'foo~bar']])
end
it 'accepts _ in query string' do
- result = URI::parse_query_string("foo_bar=bar&bar=foo_bar")
+ result = URI::decode_www_form_18("foo_bar=bar&bar=foo_bar")
result.should eq([['foo_bar', 'bar'], ['bar', 'foo_bar']])
end
it 'handles [ ] in query string' do
- result = URI::parse_query_string("foo[]=foo&foo[]=bar")
+ result = URI::decode_www_form_18("foo[]=foo&foo[]=bar")
result.should eq([['foo[]', 'foo'], ['foo[]', 'bar']])
end
it 'returns an empty array, if query string is empty' do
- result = URI::parse_query_string("")
+ result = URI::decode_www_form_18("")
result.should eq([])
end
it 'throws an error, if more than one = without an & or ; in between' do
expect {
- result = URI::parse_query_string("foo=bar=foo&bar=foo=bar")
+ result = URI::decode_www_form_18("foo=bar=foo&bar=foo=bar")
}.to raise_error(
ArgumentError,
"invalid data of application/x-www-form-urlencoded "+
@@ -126,7 +128,7 @@ describe URI, '#parse_query_string' do
it 'throws an error, if more than one & without an = in between' do
expect {
- result = URI::parse_query_string("foo&bar=foo&bar")
+ result = URI::decode_www_form_18("foo&bar=foo&bar")
}.to raise_error(
ArgumentError,
"invalid data of application/x-www-form-urlencoded (foo&bar=foo&bar)"
@@ -135,7 +137,7 @@ describe URI, '#parse_query_string' do
it 'throws an error, if more than one ; without an = in between' do
expect {
- result = URI::parse_query_string("foo;bar=foo;bar")
+ result = URI::decode_www_form_18("foo;bar=foo;bar")
}.to raise_error(
ArgumentError,
"invalid data of application/x-www-form-urlencoded (foo;bar=foo;bar)"