praxis 2.0.pre.12 → 2.0.pre.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf4b54b686373509e0920a93d482e29f4c198491f88d382b6ff429e5128d6574
4
- data.tar.gz: '08b2d7342069e8584676e03c828e144b99eb9282b193113b987d8060cb143cfd'
3
+ metadata.gz: c4be08481cbad0604fdb8e45dfc66aec895478a0b7578544b773af7fa6f3863f
4
+ data.tar.gz: 122625c252f5d9a2166e8958408bedf7ac5aee13500488e44c453ddeff3fbcc8
5
5
  SHA512:
6
- metadata.gz: ef7cd7fe985d4af76cf7ec6459e58990b8dbc6f3c4fac5c26ce04d56e23a3d743a0f4bb776f4d5c913224e031567e9993ad52e611e4258ee853cdf86b3099255
7
- data.tar.gz: f4fe45f97c9bc26aa513a24ee358b04dc114af0e7f4849071f699c0c22df460253452dd54e9bcb510fc4f977aa9104774f70c882f46b8aa937404e79814d6f3d
6
+ metadata.gz: 6472e4ef1f9ad601ed5c13774a336b93d52356a3a0bccb3a3707953658918a79457d314ceca1ce676a15f51c10bcebb4556388c95ba3aeca2cbec40625b13734
7
+ data.tar.gz: d8a4bad9469579530974d3c61d61fd7441b4e9d48d2ecb90ac81d4951cda0293428f750011e406e755103abb162b4fb1c60b87a584fe77da74c68dafaa997ecd
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## next
4
4
 
5
+ ## 2.0.pre.13
6
+
7
+ * Fix filters parser regression, which would incorrectly decode url-encoded values
8
+
5
9
  ## 2.0.pre.12
6
10
 
7
11
  * Rebuilt API filters to support a much richer syntax. One can now use ANDs and ORs (with ANDs having order precedence), as well as group them with parenthesis. The same individual filter operands are supported. For example: 'email=*@gmail.com&(friends.first_name=Joe*,Patty|friends.last_name=Smith)
@@ -160,7 +160,8 @@ module Praxis
160
160
  return filters if filters.is_a?(native_type)
161
161
  return new if filters.nil? || filters.blank?
162
162
 
163
- parsed = Parser.new.parse(CGI.unescape(filters))
163
+ parsed = Parser.new.parse(filters)
164
+
164
165
  tree = ConditionGroup.load(parsed)
165
166
 
166
167
  rr = tree.flattened_conditions
@@ -24,9 +24,9 @@ module Praxis
24
24
  @values = if values.empty?
25
25
  ""
26
26
  elsif values.size == 1
27
- values.first[:value].to_s
27
+ CGI.unescape(values.first[:value].to_s)
28
28
  else
29
- values.map{|e| e[:value].to_s}
29
+ values.map{|e| CGI.unescape(e[:value].to_s)}
30
30
  end
31
31
  else # No values for the operand
32
32
  @name = triad[:name].to_sym
@@ -36,7 +36,7 @@ module Praxis
36
36
  else
37
37
  # Value operand without value? => convert it to empty string
38
38
  raise "Interesting, didn't know this could happen. Oops!" if triad[:value].is_a?(Array) && !triad[:value].empty?
39
- @values = (triad[:value] == []) ? '' : triad[:value].to_s # TODO: could this be an array (or it always comes the other if)
39
+ @values = (triad[:value] == []) ? '' : CGI.unescape(triad[:value].to_s) # TODO: could this be an array (or it always comes the other if)
40
40
  end
41
41
  end
42
42
  end
@@ -1,3 +1,3 @@
1
1
  module Praxis
2
- VERSION = '2.0.pre.12'
2
+ VERSION = '2.0.pre.13'
3
3
  end
@@ -7,15 +7,30 @@ describe Praxis::Extensions::AttributeFiltering::FilteringParams do
7
7
  context '.load' do
8
8
  subject { described_class.load(filters_string) }
9
9
 
10
- it 'unescapes the URL encoded string' do
11
- str = CGI.escape("one=fun!,Times,3&two>*|three<^%$#!st_uff")
10
+ context 'unescapes the URL encoded values' do
11
+ it 'for single values' do
12
+ str = "one=#{CGI.escape('*')}&two>#{CGI.escape('^%$#!st_uff')}|three<normal"
13
+ parsed = [
14
+ { name: :one, op: '=', value: '*'},
15
+ { name: :two, op: '>', value: '^%$#!st_uff'},
16
+ { name: :three, op: '<', value: 'normal'},
17
+ ]
18
+ expect(described_class.load(str).parsed_array.map{|i| i.slice(:name,:op,:value)}).to eq(parsed)
19
+ end
20
+ it 'each of the multi-values' do
21
+ escaped_one = [
22
+ CGI.escape('fun!'),
23
+ CGI.escape('Times'),
24
+ CGI.escape('~!@#$%^&*()_+-={}|[]\:";\'<>?,./`')
25
+ ].join(',')
26
+ str = "one=#{escaped_one}&two>normal"
12
27
  parsed = [
13
- { name: :one, op: '=', value: ["fun!","Times","3"]},
14
- { name: :two, op: '>', value: "*"},
15
- { name: :three, op: '<', value: "^%$#!st_uff"},
28
+ { name: :one, op: '=', value: ['fun!','Times','~!@#$%^&*()_+-={}|[]\:";\'<>?,./`']},
29
+ { name: :two, op: '>', value: 'normal'},
16
30
  ]
17
31
  expect(described_class.load(str).parsed_array.map{|i| i.slice(:name,:op,:value)}).to eq(parsed)
18
32
  end
33
+ end
19
34
  context 'parses for operator' do
20
35
  described_class::VALUE_OPERATORS.each do |op|
21
36
  it "#{op}" do
@@ -118,14 +118,23 @@ describe Praxis::Extensions::AttributeFiltering::FilteringParams::Parser do
118
118
  'cOrN.00copia.of_thinGs.42_here=1' => 'cOrN.00copia.of_thinGs.42_here=1',
119
119
  }
120
120
  end
121
- context 'supports everything (except &|(),) for values' do
121
+ context 'supports everything (except &|(),) for values (even without encoding..not allowed, but just to ensure the parser does not bomb)' do
122
122
  it_behaves_like 'round-trip-properly', {
123
123
  'v=1123' => 'v=1123',
124
124
  'v=*foo*' => 'v=*foo*',
125
125
  'v=*^%$#@!foo' => 'v=*^%$#@!foo',
126
- 'v=_-+=\{}"?:><' => 'v=_-+=\{}"?:><',
127
- 'v=_-+=\{}"?:><,another_value!' => 'v=[_-+=\{}"?:><,another_value!]',
126
+ 'v=_-=\{}"?:><' => 'v=_-=\{}"?:><',
127
+ 'v=_-=\{}"?:><,another_value!' => 'v=[_-=\{}"?:><,another_value!]',
128
128
  }
129
129
  end
130
+ context 'properly handles url-encoded values' do
131
+ it_behaves_like 'round-trip-properly', {
132
+ "v=#{CGI.escape('1123')}" => 'v=1123',
133
+ "v=#{CGI.escape('*foo*')}" => 'v=*foo*',
134
+ "v=#{CGI.escape('*^%$#@!foo')}" => 'v=*^%$#@!foo',
135
+ "v=#{CGI.escape('~!@#$%^&*()_+-={}|[]\:";\'<>?,./`')}" => 'v=~!@#$%^&*()_+-={}|[]\:";\'<>?,./`',
136
+ "v=#{CGI.escape('_-+=\{}"?:><')},#{CGI.escape('another_value!')}" => 'v=[_-+=\{}"?:><,another_value!]',
137
+ }
138
+ end
130
139
  end
131
140
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: praxis
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.pre.12
4
+ version: 2.0.pre.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep M. Blanquer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-02-23 00:00:00.000000000 Z
12
+ date: 2021-02-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack