groovy 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/groovy/query.rb +4 -2
- data/lib/groovy/version.rb +1 -1
- data/spec/query_spec.rb +13 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2e7655a8fefa2f17295105acb6ba387f275eb158c0babed04675d566f736766
|
4
|
+
data.tar.gz: 5a9b94a767f58b033a11044d3b7992911a6cde0ad068955c76d85bdd2c0464b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c8813e0920559c6422f8129ca40e51c42a6db26efc65c9f2d9a1d47d8f5f6d5638f9677f970a38d36a180c93cf610b99b7adc372579eaff92ae4d8bd9aa41ae
|
7
|
+
data.tar.gz: d12ed329507b8a5c191308e198a5434f8226fd24bf4f25c8b2b8d64a832c05df39ff9946dddd53b7da5df11c2d14bc9ab97e4dcf84d67e60c9c2811d0c0122b6
|
data/lib/groovy/query.rb
CHANGED
@@ -6,6 +6,7 @@ module Groovy
|
|
6
6
|
AND = '+'.freeze
|
7
7
|
NOT = '-'.freeze
|
8
8
|
PER_PAGE = 50.freeze
|
9
|
+
# ESCAPE_CHARS_REGEX = /([\(\)\/\\])/.freeze
|
9
10
|
VALID_QUERY_CHARS = 'a-zA-Z0-9_\.,&-'.freeze
|
10
11
|
REMOVE_INVALID_CHARS_REGEX = Regexp.new('[^\s' + VALID_QUERY_CHARS + ']').freeze
|
11
12
|
|
@@ -81,7 +82,7 @@ module Groovy
|
|
81
82
|
add_param(AND + [key, val.max].join(':<=')) if val.max # gte
|
82
83
|
|
83
84
|
elsif val.is_a?(Regexp)
|
84
|
-
str = val.source.gsub(REMOVE_INVALID_CHARS_REGEX, '')
|
85
|
+
str = val.source.gsub('/', '_slash_').gsub('(', '_openp_').gsub(')', '_closep_').gsub(REMOVE_INVALID_CHARS_REGEX, '')
|
85
86
|
param = val.source[0] == '^' ? ':^' : val.source[-1] == '$' ? ':$' : ':~' # starts with or regexp
|
86
87
|
add_param(AND + [key, str.downcase].join(param)) # regex must be downcase
|
87
88
|
|
@@ -115,7 +116,7 @@ module Groovy
|
|
115
116
|
add_param(AND + [key, val.max].join(':>=')) if val.max # lte, nil if range.max is -1
|
116
117
|
|
117
118
|
elsif val.is_a?(Regexp)
|
118
|
-
str = val.source.gsub(REMOVE_INVALID_CHARS_REGEX, '')
|
119
|
+
str = val.source.gsub('/', '_slash_').gsub('(', '_openp_').gsub(')', '_closep_').gsub(REMOVE_INVALID_CHARS_REGEX, '')
|
119
120
|
param = val.source[0] == '^' ? ':^' : val.source[-1] == '$' ? ':$' : ':~' # starts with or regexp
|
120
121
|
add_param(NOT + [key, str.downcase].join(param)) # regex must be downcase
|
121
122
|
|
@@ -296,6 +297,7 @@ module Groovy
|
|
296
297
|
query = parameters.join(' ').split(/ or /i).map do |part|
|
297
298
|
part.gsub(' ', ' ') # replace double with single spaces
|
298
299
|
.gsub(space_regex, '\ \1') # escape spaces before word letters
|
300
|
+
.gsub('_slash_', '\/').gsub('_openp_', '\(').gsub('_closep_', '\)')
|
299
301
|
.gsub(/(\d\d):(\d\d):(\d\d)/, '\1\:\2\:\3') # escape hh:mm:ss in timestamps
|
300
302
|
end.join(' OR ').sub(/^-/, '_id:>0 -') #.gsub(' OR -', ' -')
|
301
303
|
end
|
data/lib/groovy/version.rb
CHANGED
data/spec/query_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe Groovy::Query do
|
|
8
8
|
@p1 = TestProduct.create!(name: "Product 1", visible: true, price: 10, tag_list: 'one, number two & three')
|
9
9
|
@p2 = TestProduct.create!(name: "Product 2", visible: false, price: 20, tag_list: 'number two, three')
|
10
10
|
@p3 = TestProduct.create!(name: "Product 3: The Best", visible: true, price: 30, tag_list: nil)
|
11
|
-
@p4 = TestProduct.create!(name: "Product 4", visible: false, price: 40, tag_list: 'one, number two')
|
11
|
+
@p4 = TestProduct.create!(name: "Product 4", visible: false, price: 40, tag_list: 'one, number two / something')
|
12
12
|
@p5 = TestProduct.create!(name: "Product 5", visible: true, price: 50, tag_list: '')
|
13
13
|
end
|
14
14
|
|
@@ -124,6 +124,12 @@ describe Groovy::Query do
|
|
124
124
|
res = TestProduct.where(tag_list: /two & three/)
|
125
125
|
expect(res.map(&:id)).to eq([@p1.id])
|
126
126
|
end
|
127
|
+
|
128
|
+
it 'works with slashes' do
|
129
|
+
str = 'two / something'
|
130
|
+
res = TestProduct.where(tag_list: /#{str}/)
|
131
|
+
expect(res.map(&:id)).to eq([@p4.id])
|
132
|
+
end
|
127
133
|
end
|
128
134
|
|
129
135
|
describe 'starts with regex' do
|
@@ -253,6 +259,12 @@ describe Groovy::Query do
|
|
253
259
|
res = TestProduct.not(tag_list: /two & three/)
|
254
260
|
expect(res.map(&:id)).to eq([@p2.id, @p3.id, @p4.id, @p5.id])
|
255
261
|
end
|
262
|
+
|
263
|
+
it 'works with slashes' do
|
264
|
+
str = 'two / something'
|
265
|
+
res = TestProduct.not(tag_list: /#{str}/)
|
266
|
+
expect(res.map(&:id)).to eq([@p1.id, @p2.id, @p3.id, @p5.id])
|
267
|
+
end
|
256
268
|
end
|
257
269
|
|
258
270
|
describe 'starts with regex' do
|