summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorStormwind <stormwind@stormwinds-page.de>2012-12-22 13:09:15 +0100
committerStormwind <stormwind@stormwinds-page.de>2012-12-22 13:09:15 +0100
commitbfca378f8f6c24fac252ac94b3ce6d4e0dd75d9d (patch)
tree3902c0497c182f10e977720a3fa50a84db5c3ea2 /lib
parent443958f8859a47751f7e57deff6b3eda0c13e5ad (diff)
Add first implementation of decode_www_form_18
Seperates now foo=bar&bar=foo;baz=foo queries. But does not fix url encoded strings and such things. Also added testcase for an empty query string.
Diffstat (limited to 'lib')
-rw-r--r--lib/zero/patches/uri.rb27
1 files changed, 26 insertions, 1 deletions
diff --git a/lib/zero/patches/uri.rb b/lib/zero/patches/uri.rb
index fb821b2..2545e34 100644
--- a/lib/zero/patches/uri.rb
+++ b/lib/zero/patches/uri.rb
@@ -14,7 +14,32 @@ module URI
end
# else split the query self
- return []
+ return self.decode_www_form_18 query
+ end
+
+ # Own implementation of decode_www_form.
+ # Shall behave almost like the original method, but without any encoding
+ # stuff.
+ #
+ # @param [String] query The query string
+ # @return [Array] Parsed query
+ #
+ def self.decode_www_form_18(query)
+ return [] if query.empty?
+ unless query.match '='
+ raise ArgumentError,
+ "invalid data of application/x-www-form-urlencoded (#{query})"
+ end
+ parsed = []
+ # breakes the string at & and ;
+ query.split(/[&;]/).each do |query_part|
+ # breakes the string parts at =
+ key, value = query_part.split('=')
+ # append the key value pair on the result array
+ parsed << [key, value]
+ end
+ # return result array
+ return parsed
end
=begin