faraday 2.14.2 → 2.14.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05f10cf15f3eb3f35b39edc67e14c374306d286f7b282ce86e131cab66ef9726
4
- data.tar.gz: 17df5c4c9c054080f80038a1d8c6e1eaf88fd5d319c5ca1f04b10bc7bc0fe350
3
+ metadata.gz: ecc5e9592d7434d7e39bc5cc827be5b62af99e258582468c8b6fd78e0122bf7e
4
+ data.tar.gz: 4f5728ac524a3456a800c8d0159b4569173b1c841f80fae7d0d2704e261b6588
5
5
  SHA512:
6
- metadata.gz: 511bc21e7d0e4c4ecf866f84b434e6f38d6c4eada9d17148f25db9c6cf3194c4fe6fe600cc1b41d288e611e8dbfcbbbb5e2d711051a4340239741bb9dae54b73
7
- data.tar.gz: e527f43b558124d58d4c4826dc46d0716a6689fec48dea4daf47a3943e1cae5c3612b2e490c956811d0d2ba501290548e85f2b0879bd924fd026566a2dc6056e
6
+ metadata.gz: 12567175cd7d08a95ccf8203bffcb9bebf8d1b52f279ce034c3f3e17dc5efc81e08259c2992ff792560ed626dd59ae305c163cb43018860b3c0ae833c3f68855
7
+ data.tar.gz: bb786c688b4629c6bc43e4715715fcd42de120eee3802a3614eca60e17627ff77f40298af500a431158b1f1de8bd0d0bd58817a8793bab92e11bac9aa9b482f2
@@ -127,6 +127,14 @@ module Faraday
127
127
  new_stub(:options, path, headers, &block)
128
128
  end
129
129
 
130
+ # Removes all stubs, including the ones that have already been consumed.
131
+ def clear
132
+ @stubs_mutex.synchronize do
133
+ @stack.clear
134
+ @consumed.clear
135
+ end
136
+ end
137
+
130
138
  # Raises an error if any of the stubbed calls have not been made.
131
139
  def verify_stubbed_calls
132
140
  failed_stubs = []
@@ -106,6 +106,8 @@ module Faraday
106
106
 
107
107
  def decode_pair(key, value, context)
108
108
  subkeys = key.scan(SUBKEYS_REGEX)
109
+ validate_params_depth!(subkeys.length)
110
+
109
111
  subkeys.each_with_index do |subkey, i|
110
112
  is_array = subkey =~ /[\[\]]+\Z/
111
113
  subkey = Regexp.last_match.pre_match if is_array
@@ -145,6 +147,12 @@ module Faraday
145
147
  is_array ? context << value : context[subkey] = value
146
148
  end
147
149
 
150
+ def validate_params_depth!(depth)
151
+ return unless @param_depth_limit && depth > @param_depth_limit
152
+
153
+ raise Faraday::Error, "exceeded nested parameter depth limit of #{@param_depth_limit}"
154
+ end
155
+
148
156
  # Internal: convert a nested hash with purely numeric keys into an array.
149
157
  # FIXME: this is not compatible with Rack::Utils.parse_nested_query
150
158
  # @!visibility private
@@ -167,7 +175,7 @@ module Faraday
167
175
  # for your requests.
168
176
  module NestedParamsEncoder
169
177
  class << self
170
- attr_accessor :sort_params, :array_indices
178
+ attr_accessor :sort_params, :array_indices, :param_depth_limit
171
179
 
172
180
  extend Forwardable
173
181
 
@@ -177,6 +185,7 @@ module Faraday
177
185
  # Useful default for OAuth and caching.
178
186
  @sort_params = true
179
187
  @array_indices = false
188
+ @param_depth_limit = 100
180
189
 
181
190
  extend EncodeMethods
182
191
  extend DecodeMethods
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Faraday
4
- VERSION = '2.14.2'
4
+ VERSION = '2.14.3'
5
5
  end
@@ -439,4 +439,22 @@ RSpec.describe Faraday::Adapter::Test do
439
439
  end
440
440
  end
441
441
  end
442
+
443
+ describe '#clear' do
444
+ it 'removes pending stubs' do
445
+ stubs.clear
446
+ expect { connection.get('/hello') }.to raise_error(described_class::Stubs::NotFound)
447
+ end
448
+
449
+ it 'removes already consumed stubs' do
450
+ expect(connection.get('/hello').body).to eq('hello')
451
+ stubs.clear
452
+ expect { connection.get('/hello') }.to raise_error(described_class::Stubs::NotFound)
453
+ end
454
+
455
+ it 'leaves the stubs empty' do
456
+ stubs.clear
457
+ expect(stubs).to be_empty
458
+ end
459
+ end
442
460
  end
@@ -380,6 +380,18 @@ RSpec.describe Faraday::Connection do
380
380
  url = conn.build_url(nil, b: 2, c: 3)
381
381
  expect(url.to_s).to eq('http://httpbingo.org/nigiri?a=1&b=2&c=3')
382
382
  end
383
+
384
+ it 'raises a controlled error when URL query params exceed the nested depth limit' do
385
+ original_param_depth_limit = Faraday::NestedParamsEncoder.param_depth_limit
386
+ Faraday::NestedParamsEncoder.param_depth_limit = 2
387
+
388
+ expect { conn.build_url('/nigiri?a[b][c]=1') }.to raise_error(
389
+ Faraday::Error,
390
+ 'exceeded nested parameter depth limit of 2'
391
+ )
392
+ ensure
393
+ Faraday::NestedParamsEncoder.param_depth_limit = original_param_depth_limit
394
+ end
383
395
  end
384
396
 
385
397
  describe '#build_request' do
@@ -5,6 +5,13 @@ require 'rack/utils'
5
5
  RSpec.describe Faraday::NestedParamsEncoder do
6
6
  it_behaves_like 'a params encoder'
7
7
 
8
+ around do |example|
9
+ original_param_depth_limit = described_class.param_depth_limit
10
+ example.run
11
+ ensure
12
+ described_class.param_depth_limit = original_param_depth_limit
13
+ end
14
+
8
15
  it 'decodes arrays' do
9
16
  query = 'a[1]=one&a[2]=two&a[3]=three'
10
17
  expected = { 'a' => %w[one two three] }
@@ -53,6 +60,27 @@ RSpec.describe Faraday::NestedParamsEncoder do
53
60
  expect(subject.decode(query)).to eq(expected)
54
61
  end
55
62
 
63
+ it 'allows nested params within the configured depth limit' do
64
+ described_class.param_depth_limit = 3
65
+
66
+ expect(subject.decode('a[b][c]=1')).to eq({ 'a' => { 'b' => { 'c' => '1' } } })
67
+ end
68
+
69
+ it 'raises a controlled error when nested params exceed the depth limit' do
70
+ described_class.param_depth_limit = 2
71
+
72
+ expect { subject.decode('a[b][c]=1') }.to raise_error(
73
+ Faraday::Error,
74
+ 'exceeded nested parameter depth limit of 2'
75
+ )
76
+ end
77
+
78
+ it 'allows disabling the nested params depth limit' do
79
+ described_class.param_depth_limit = nil
80
+
81
+ expect(subject.decode('a[b][c][d]=1')).to eq({ 'a' => { 'b' => { 'c' => { 'd' => '1' } } } })
82
+ end
83
+
56
84
  it 'decodes nested final value overrides any type' do
57
85
  query = 'a[b][c]=1&a[b]=2'
58
86
  expected = { 'a' => { 'b' => '2' } }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.14.2
4
+ version: 2.14.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - "@technoweenie"
@@ -144,7 +144,7 @@ licenses:
144
144
  - MIT
145
145
  metadata:
146
146
  homepage_uri: https://lostisland.github.io/faraday
147
- changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.14.2
147
+ changelog_uri: https://github.com/lostisland/faraday/releases/tag/v2.14.3
148
148
  source_code_uri: https://github.com/lostisland/faraday
149
149
  bug_tracker_uri: https://github.com/lostisland/faraday/issues
150
150
  rubygems_mfa_required: 'true'