diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-01 12:57:16 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2004-12-01 12:57:16 +0000 |
commit | 50f333b203756009acff2457b6d1c9da3b532cad (patch) | |
tree | 14394927c17e2bdf212fbe77c8fb7deed7c6d4bd /actionpack/lib/action_controller/cgi_ext | |
parent | 79e85edd71a4c886b1ac074988963588d8c45755 (diff) | |
download | rails-50f333b203756009acff2457b6d1c9da3b532cad.tar.gz rails-50f333b203756009acff2457b6d1c9da3b532cad.tar.bz2 rails-50f333b203756009acff2457b6d1c9da3b532cad.zip |
Added graceful handling of non-alphanumeric names and misplaced brackets in input parameters [bitsweat]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@39 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_controller/cgi_ext')
-rwxr-xr-x | actionpack/lib/action_controller/cgi_ext/cgi_methods.rb | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb b/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb index 261490580c..3736353b53 100755 --- a/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb +++ b/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb @@ -63,29 +63,27 @@ class CGIMethods #:nodoc: end end - def CGIMethods.get_levels(key_string) - return [] if key_string.nil? or key_string.empty? - - levels = [] - main, existance = /(\w+)(\[)?.?/.match(key_string).captures - levels << main - - unless existance.nil? - hash_part = key_string.sub(/\w+\[/, "") - hash_part.slice!(-1, 1) - levels += hash_part.split(/\]\[/) + PARAMS_HASH_RE = /^([^\[]+)(\[.*\])?(.)?.*$/ + def CGIMethods.get_levels(key) + all, main, bracketed, trailing = PARAMS_HASH_RE.match(key).to_a + if main.nil? + [] + elsif trailing + [key] + elsif bracketed + [main] + bracketed.slice(1...-1).split('][') + else + [main] end - - levels end - + def CGIMethods.build_deep_hash(value, hash, levels) if levels.length == 0 - value; + value elsif hash.nil? { levels.first => CGIMethods.build_deep_hash(value, nil, levels[1..-1]) } else hash.update({ levels.first => CGIMethods.build_deep_hash(value, hash[levels.first], levels[1..-1]) }) end end -end
\ No newline at end of file +end |