protocol-url 0.7.0 → 0.8.0

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: 38bcf53ee312963527020be6c4a4c18697587ad4ecd75277552b1dbd744e0ec9
4
- data.tar.gz: 85f2886788dfec25b6799f3c92d79f8bb31fbb5f48f3b017fca94993a21b507b
3
+ metadata.gz: 0e251b8fa72bc3017a56cfa385bf2bc7b9e1e4ef8add2bcd12fb8321cc349c75
4
+ data.tar.gz: 700835c1db54aead624eb89003c7daa42d9ad992f7139c336e2a5293291db619
5
5
  SHA512:
6
- metadata.gz: c5870caa5923cc4918e909470522231f132946f3235a8b396dff155adcab311ab0a1743da9ae1de96c92d2427c6e61cb758760dc2a3133005c4b0929225a4af5
7
- data.tar.gz: 820c6b061491cd83b553f38b5d53573cc641d76ad63be859e2835698e0b7242ae908763758b1730dd3b56a3f5a82dfe11d2f2de0cfafe12bd87ef66d4e405c17
6
+ metadata.gz: 6285b5b91ba997d2f822fcc4ffd49b96dffcc1336483bd043f42a736dfb3bbe4e145e492044a201de1c8f0f3e363ae816d64af79e0412b2ce4715ec69e3b4d9c
7
+ data.tar.gz: 6e4c0817905afb9b17e8e0eceae42e7ea24d6c0af6a57773d7395355b2e7b597d043c9d7795ddf62194790f0a3f53f6346d7950598721c4b079e7a419e95f793
checksums.yaml.gz.sig CHANGED
Binary file
@@ -10,13 +10,13 @@ module Protocol
10
10
  module FormData
11
11
  # Builds nested form data from names and values.
12
12
  class Nested
13
- # The default maximum depth of a bracketed form name.
14
- MAXIMUM_DEPTH = 8
13
+ # The bracketed form name depth limit.
14
+ DEPTH_LIMIT = 8
15
15
 
16
16
  # Initialize the nested form data.
17
- # @parameter maximum_depth [Integer | Nil] The maximum depth of a bracketed form name.
18
- def initialize(maximum_depth: MAXIMUM_DEPTH)
19
- @maximum_depth = maximum_depth
17
+ # @parameter depth_limit [Integer | Nil] The bracketed form name depth limit.
18
+ def initialize(depth_limit: DEPTH_LIMIT)
19
+ @depth_limit = depth_limit
20
20
  @root = {}
21
21
  end
22
22
 
@@ -31,8 +31,8 @@ module Protocol
31
31
  raise ArgumentError, "Invalid form data name: #{name.inspect}!"
32
32
  end
33
33
 
34
- if @maximum_depth and keys.size > @maximum_depth
35
- raise RangeError, "Form data depth exceeded limit of #{@maximum_depth}!"
34
+ if @depth_limit and keys.size > @depth_limit
35
+ raise RangeError, "Form data depth exceeded limit of #{@depth_limit}!"
36
36
  end
37
37
 
38
38
  Encoding.assign(keys, value, @root)
@@ -13,20 +13,20 @@ module Protocol
13
13
  class Parser
14
14
  CONTENT_TYPE = "application/x-www-form-urlencoded"
15
15
 
16
- # The default maximum encoded body size.
17
- MAXIMUM_TOTAL_SIZE = 2 * 1024 * 1024
16
+ # The encoded body size limit.
17
+ SIZE_LIMIT = 2 * 1024 * 1024
18
18
 
19
- # The default maximum number of form pairs.
20
- MAXIMUM_PAIR_COUNT = 1024
19
+ # The form pair count limit.
20
+ PAIR_COUNT_LIMIT = 1024
21
21
 
22
22
  # Initialize the form data parser.
23
- # @parameter maximum_total_size [Integer | Nil] The maximum encoded body size.
24
- # @parameter maximum_pair_count [Integer | Nil] The maximum number of form pairs.
25
- # @parameter maximum_depth [Integer | Nil] The maximum depth of a bracketed form name.
26
- def initialize(maximum_total_size: MAXIMUM_TOTAL_SIZE, maximum_pair_count: MAXIMUM_PAIR_COUNT, maximum_depth: Nested::MAXIMUM_DEPTH)
27
- @maximum_total_size = maximum_total_size
28
- @maximum_pair_count = maximum_pair_count
29
- @maximum_depth = maximum_depth
23
+ # @parameter size_limit [Integer | Nil] The encoded body size limit.
24
+ # @parameter pair_count_limit [Integer | Nil] The form pair count limit.
25
+ # @parameter depth_limit [Integer | Nil] The bracketed form name depth limit.
26
+ def initialize(size_limit: SIZE_LIMIT, pair_count_limit: PAIR_COUNT_LIMIT, depth_limit: Nested::DEPTH_LIMIT)
27
+ @size_limit = size_limit
28
+ @pair_count_limit = pair_count_limit
29
+ @depth_limit = depth_limit
30
30
  end
31
31
 
32
32
  # Parse URL-encoded form data into a nested hash.
@@ -54,14 +54,14 @@ module Protocol
54
54
  return to_enum(__method__, body) unless block_given?
55
55
 
56
56
  buffer = String.new.b
57
- total_size = 0
57
+ size = 0
58
58
  pair_count = 0
59
59
 
60
60
  while chunk = body.read
61
61
  break if chunk.empty?
62
62
 
63
- total_size += chunk.bytesize
64
- check_limit(:total_size, total_size, @maximum_total_size)
63
+ size += chunk.bytesize
64
+ check_limit(:size, size, @size_limit)
65
65
  buffer << chunk
66
66
 
67
67
  while separator = buffer.index("&")
@@ -70,7 +70,7 @@ module Protocol
70
70
 
71
71
  unless assignment.empty?
72
72
  pair_count += 1
73
- check_limit(:pair_count, pair_count, @maximum_pair_count)
73
+ check_limit(:pair_count, pair_count, @pair_count_limit)
74
74
  yield_pair(assignment) {|name, value| yield name, value}
75
75
  end
76
76
  end
@@ -78,7 +78,7 @@ module Protocol
78
78
 
79
79
  unless buffer.empty?
80
80
  pair_count += 1
81
- check_limit(:pair_count, pair_count, @maximum_pair_count)
81
+ check_limit(:pair_count, pair_count, @pair_count_limit)
82
82
  yield_pair(buffer) {|name, value| yield name, value}
83
83
  end
84
84
 
@@ -88,7 +88,7 @@ module Protocol
88
88
  private
89
89
 
90
90
  def make_result
91
- return Nested.new(maximum_depth: @maximum_depth)
91
+ return Nested.new(depth_limit: @depth_limit)
92
92
  end
93
93
 
94
94
  def yield_pair(assignment)
@@ -105,9 +105,9 @@ module Protocol
105
105
  return Encoding.unescape(component.tr("+", " "))
106
106
  end
107
107
 
108
- def check_limit(name, value, maximum)
109
- if maximum and value > maximum
110
- raise RangeError, "Form data #{name} exceeded limit of #{maximum}!"
108
+ def check_limit(name, value, limit)
109
+ if limit and value > limit
110
+ raise RangeError, "Form data #{name} exceeded limit of #{limit}!"
111
111
  end
112
112
  end
113
113
  end
@@ -7,6 +7,6 @@
7
7
  module Protocol
8
8
  # @namespace
9
9
  module URL
10
- VERSION = "0.7.0"
10
+ VERSION = "0.8.0"
11
11
  end
12
12
  end
data/readme.md CHANGED
@@ -34,6 +34,10 @@ This project is best served by a collaborative and respectful environment. Treat
34
34
 
35
35
  Please see the [project releases](https://socketry.github.io/protocol-url/releases/index) for all releases.
36
36
 
37
+ ### v0.8.0
38
+
39
+ - Use consistent limit naming for form data parser constraints.
40
+
37
41
  ### v0.7.0
38
42
 
39
43
  - Allow `Protocol::URL::FormData::Parser#parse` to populate a supplied result object.
data/releases.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Releases
2
2
 
3
+ ## v0.8.0
4
+
5
+ - Use consistent limit naming for form data parser constraints.
6
+
3
7
  ## v0.7.0
4
8
 
5
9
  - Allow `Protocol::URL::FormData::Parser#parse` to populate a supplied result object.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-url
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
metadata.gz.sig CHANGED
Binary file