Permalink
Browse files

Unescaping values of all parameters before parsing them

  • Loading branch information...
1 parent b6ce16e commit daa1e469d0418570b23170b4f61f1ccb178c5016 @vicentemundim committed Aug 18, 2010
Showing with 10 additions and 2 deletions.
  1. +5 −1 lib/mongoid_query_string_interface.rb
  2. +1 −1 lib/version.rb
  3. +4 −0 spec/mongoid_query_string_interface_spec.rb
View
6 lib/mongoid_query_string_interface.rb
@@ -58,7 +58,7 @@ def parse_operators(options)
attribute = attribute_from(key)
operator = operator_from(key)
- value = parse_value(value, operator)
+ value = parse_value(unescape(value), operator)
if operator
filter = { operator => value }
@@ -89,6 +89,10 @@ def operator_from(key)
"$#{match[1]}".to_sym
end
end
+
+ def unescape(value)
+ URI.unescape(value)
+ end
def parse_value(value, operator)
parse_date(value) or parse_integer(value) or parse_float(value) or parse_array(value, operator) or parse_regex(value) or value
View
2 lib/version.rb
@@ -1,6 +1,6 @@
# encoding: utf-8
module Mongoid #:nodoc
module QueryStringInterface #:nodoc
- VERSION = "0.1.5"
+ VERSION = "0.1.6"
end
end
View
4 spec/mongoid_query_string_interface_spec.rb
@@ -162,6 +162,10 @@ class EmbeddedDocument
lambda { Document.filter_by('title' => '') }.should_not raise_error
end
+ it 'should unescape all values in the URI' do
+ Document.filter_by('title' => 'Some%20Title').should == [document]
+ end
+
context 'with conditional operators' do
it 'should use it when given as the last portion of attribute name' do
Document.filter_by('title.ne' => 'Some Other Title').should == [document]

0 comments on commit daa1e46

Please sign in to comment.