data_table 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,10 +13,12 @@ module DataTable
13
13
  end
14
14
 
15
15
  def _where_conditions raw_query, search_fields
16
- return if (query = raw_query.gsub(/\//, "")).blank?
16
+ query = _sanitize raw_query
17
+ ::Rails.logger.info "#{raw_query.inspect} => #{query.inspect}"
18
+ return if (query = _sanitize raw_query).blank?
17
19
 
18
20
  if search_fields.size == 1
19
- terms = query.strip.split(/\s+/)
21
+ terms = query.split(/\s+/)
20
22
 
21
23
  if terms.size == 1
22
24
  {search_fields.first => /#{terms.first}/i}
@@ -31,6 +33,10 @@ module DataTable
31
33
  def _order_by_fields params, fields
32
34
  [fields[params[:iSortCol_0].to_i], params[:sSortDir_0]]
33
35
  end
36
+
37
+ def _sanitize string
38
+ string.strip.gsub(/([\/\.\+\*\[\]\(\)])/) { "\\#{$1}" }
39
+ end
34
40
  end
35
41
  end
36
42
  end
@@ -1,3 +1,3 @@
1
1
  module DataTable
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
@@ -25,10 +25,6 @@ describe DataTable do
25
25
  send(:_where_conditions, "", %w(foo bar baz)).should == nil
26
26
  end
27
27
 
28
- it "should strip out slashes" do
29
- send(:_where_conditions, "//", %w(foo bar baz)).should == nil
30
- end
31
-
32
28
  it "should return a mongoid $or hash with an entry for each search field" do
33
29
  send(:_where_conditions, "q", %w(foo bar)).should == {"$or" => [{"foo" => /q/i}, {"bar" => /q/i}]}
34
30
  end
@@ -58,4 +54,13 @@ describe DataTable do
58
54
  end
59
55
 
60
56
  end
57
+
58
+ context "#_sanitize" do
59
+
60
+ it "should escape characters for the regex" do
61
+ send(:_sanitize, " /.+*[]() ").should == "\\/\\.\\+\\*\\[\\]\\(\\)"
62
+ end
63
+
64
+ end
65
+
61
66
  end
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_table
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.3.3
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 4
10
+ version: 0.3.4
6
11
  platform: ruby
7
12
  authors:
8
13
  - Jason Dew
@@ -10,7 +15,7 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2011-09-05 00:00:00 -04:00
18
+ date: 2011-09-06 00:00:00 -04:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
@@ -21,6 +26,11 @@ dependencies:
21
26
  requirements:
22
27
  - - ~>
23
28
  - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 0
24
34
  version: 3.0.0
25
35
  type: :runtime
26
36
  version_requirements: *id001
@@ -32,6 +42,11 @@ dependencies:
32
42
  requirements:
33
43
  - - ~>
34
44
  - !ruby/object:Gem::Version
45
+ hash: 15
46
+ segments:
47
+ - 2
48
+ - 0
49
+ - 0
35
50
  version: 2.0.0
36
51
  type: :development
37
52
  version_requirements: *id002
@@ -43,6 +58,11 @@ dependencies:
43
58
  requirements:
44
59
  - - ~>
45
60
  - !ruby/object:Gem::Version
61
+ hash: 35
62
+ segments:
63
+ - 2
64
+ - 11
65
+ - 0
46
66
  version: 2.11.0
47
67
  type: :development
48
68
  version_requirements: *id003
@@ -54,6 +74,11 @@ dependencies:
54
74
  requirements:
55
75
  - - ~>
56
76
  - !ruby/object:Gem::Version
77
+ hash: 23
78
+ segments:
79
+ - 1
80
+ - 0
81
+ - 0
57
82
  version: 1.0.0
58
83
  type: :development
59
84
  version_requirements: *id004
@@ -100,17 +125,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
125
  requirements:
101
126
  - - ">="
102
127
  - !ruby/object:Gem::Version
128
+ hash: 3
129
+ segments:
130
+ - 0
103
131
  version: "0"
104
132
  required_rubygems_version: !ruby/object:Gem::Requirement
105
133
  none: false
106
134
  requirements:
107
135
  - - ">="
108
136
  - !ruby/object:Gem::Version
137
+ hash: 3
138
+ segments:
139
+ - 0
109
140
  version: "0"
110
141
  requirements: []
111
142
 
112
143
  rubyforge_project: data_table
113
- rubygems_version: 1.6.2
144
+ rubygems_version: 1.3.7
114
145
  signing_key:
115
146
  specification_version: 3
116
147
  summary: Simple data preparation from AR/Mongoid to the jQuery DataTables plugin