protocol-url 0.7.0 → 0.9.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: 251219144c71f40dba05ef7ad726a20b17c94beb55733317a9378e000528575b
4
+ data.tar.gz: 81be14b9dd98770859406b28a658604ea356791173c4d352d52487735364dafe
5
5
  SHA512:
6
- metadata.gz: c5870caa5923cc4918e909470522231f132946f3235a8b396dff155adcab311ab0a1743da9ae1de96c92d2427c6e61cb758760dc2a3133005c4b0929225a4af5
7
- data.tar.gz: 820c6b061491cd83b553f38b5d53573cc641d76ad63be859e2835698e0b7242ae908763758b1730dd3b56a3f5a82dfe11d2f2de0cfafe12bd87ef66d4e405c17
6
+ metadata.gz: 48b8dcae7d84dacf3bb49ce45b84d308dd2c7f0377b97e84f4d9530d4a2467d04b16a76186b3859c8fc3052da50117b197dc6a5ebc503a2568126255c234c43c
7
+ data.tar.gz: 85c632aa585bec3155f294becdee9e904b8f424bab0ef95944c15e563c7e6a5ec2a26ad8a0941ad198ce50a65fec43c84187f76dc596c6dc4bbbd879dcef7b8d
checksums.yaml.gz.sig CHANGED
Binary file
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2026, by Samuel Williams.
5
+
6
+ module Protocol
7
+ module URL
8
+ # Raised when URL processing exceeds a configured limit.
9
+ class LimitError < StandardError
10
+ end
11
+ end
12
+ end
@@ -4,19 +4,20 @@
4
4
  # Copyright, 2026, by Samuel Williams.
5
5
 
6
6
  require_relative "../encoding"
7
+ require_relative "../error"
7
8
 
8
9
  module Protocol
9
10
  module URL
10
11
  module FormData
11
12
  # Builds nested form data from names and values.
12
13
  class Nested
13
- # The default maximum depth of a bracketed form name.
14
- MAXIMUM_DEPTH = 8
14
+ # The bracketed form name depth limit.
15
+ DEPTH_LIMIT = 8
15
16
 
16
17
  # 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
18
+ # @parameter depth_limit [Integer | Nil] The bracketed form name depth limit.
19
+ def initialize(depth_limit: DEPTH_LIMIT)
20
+ @depth_limit = depth_limit
20
21
  @root = {}
21
22
  end
22
23
 
@@ -31,8 +32,8 @@ module Protocol
31
32
  raise ArgumentError, "Invalid form data name: #{name.inspect}!"
32
33
  end
33
34
 
34
- if @maximum_depth and keys.size > @maximum_depth
35
- raise RangeError, "Form data depth exceeded limit of #{@maximum_depth}!"
35
+ if @depth_limit and keys.size > @depth_limit
36
+ raise LimitError, "Form data depth exceeded limit of #{@depth_limit}!"
36
37
  end
37
38
 
38
39
  Encoding.assign(keys, value, @root)
@@ -4,6 +4,7 @@
4
4
  # Copyright, 2026, by Samuel Williams.
5
5
 
6
6
  require_relative "nested"
7
+ require_relative "../error"
7
8
 
8
9
  module Protocol
9
10
  module URL
@@ -13,20 +14,20 @@ module Protocol
13
14
  class Parser
14
15
  CONTENT_TYPE = "application/x-www-form-urlencoded"
15
16
 
16
- # The default maximum encoded body size.
17
- MAXIMUM_TOTAL_SIZE = 2 * 1024 * 1024
17
+ # The encoded body size limit.
18
+ SIZE_LIMIT = 2 * 1024 * 1024
18
19
 
19
- # The default maximum number of form pairs.
20
- MAXIMUM_PAIR_COUNT = 1024
20
+ # The form pair count limit.
21
+ PAIR_COUNT_LIMIT = 1024
21
22
 
22
23
  # 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
24
+ # @parameter size_limit [Integer | Nil] The encoded body size limit.
25
+ # @parameter pair_count_limit [Integer | Nil] The form pair count limit.
26
+ # @parameter depth_limit [Integer | Nil] The bracketed form name depth limit.
27
+ def initialize(size_limit: SIZE_LIMIT, pair_count_limit: PAIR_COUNT_LIMIT, depth_limit: Nested::DEPTH_LIMIT)
28
+ @size_limit = size_limit
29
+ @pair_count_limit = pair_count_limit
30
+ @depth_limit = depth_limit
30
31
  end
31
32
 
32
33
  # Parse URL-encoded form data into a nested hash.
@@ -54,14 +55,14 @@ module Protocol
54
55
  return to_enum(__method__, body) unless block_given?
55
56
 
56
57
  buffer = String.new.b
57
- total_size = 0
58
+ size = 0
58
59
  pair_count = 0
59
60
 
60
61
  while chunk = body.read
61
62
  break if chunk.empty?
62
63
 
63
- total_size += chunk.bytesize
64
- check_limit(:total_size, total_size, @maximum_total_size)
64
+ size += chunk.bytesize
65
+ check_limit(:size, size, @size_limit)
65
66
  buffer << chunk
66
67
 
67
68
  while separator = buffer.index("&")
@@ -70,7 +71,7 @@ module Protocol
70
71
 
71
72
  unless assignment.empty?
72
73
  pair_count += 1
73
- check_limit(:pair_count, pair_count, @maximum_pair_count)
74
+ check_limit(:pair_count, pair_count, @pair_count_limit)
74
75
  yield_pair(assignment) {|name, value| yield name, value}
75
76
  end
76
77
  end
@@ -78,7 +79,7 @@ module Protocol
78
79
 
79
80
  unless buffer.empty?
80
81
  pair_count += 1
81
- check_limit(:pair_count, pair_count, @maximum_pair_count)
82
+ check_limit(:pair_count, pair_count, @pair_count_limit)
82
83
  yield_pair(buffer) {|name, value| yield name, value}
83
84
  end
84
85
 
@@ -88,7 +89,7 @@ module Protocol
88
89
  private
89
90
 
90
91
  def make_result
91
- return Nested.new(maximum_depth: @maximum_depth)
92
+ return Nested.new(depth_limit: @depth_limit)
92
93
  end
93
94
 
94
95
  def yield_pair(assignment)
@@ -105,9 +106,9 @@ module Protocol
105
106
  return Encoding.unescape(component.tr("+", " "))
106
107
  end
107
108
 
108
- def check_limit(name, value, maximum)
109
- if maximum and value > maximum
110
- raise RangeError, "Form data #{name} exceeded limit of #{maximum}!"
109
+ def check_limit(name, value, limit)
110
+ if limit and value > limit
111
+ raise LimitError, "Form data #{name} exceeded limit of #{limit}!"
111
112
  end
112
113
  end
113
114
  end
@@ -7,6 +7,6 @@
7
7
  module Protocol
8
8
  # @namespace
9
9
  module URL
10
- VERSION = "0.7.0"
10
+ VERSION = "0.9.0"
11
11
  end
12
12
  end
data/lib/protocol/url.rb CHANGED
@@ -4,6 +4,7 @@
4
4
  # Copyright, 2025, by Samuel Williams.
5
5
 
6
6
  require_relative "url/version"
7
+ require_relative "url/error"
7
8
  require_relative "url/pattern"
8
9
  require_relative "url/encoding"
9
10
  require_relative "url/form_data/nested"
data/readme.md CHANGED
@@ -34,6 +34,14 @@ 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.9.0
38
+
39
+ - Add `Protocol::URL::LimitError` for configured processing limits.
40
+
41
+ ### v0.8.0
42
+
43
+ - Use consistent limit naming for form data parser constraints.
44
+
37
45
  ### v0.7.0
38
46
 
39
47
  - Allow `Protocol::URL::FormData::Parser#parse` to populate a supplied result object.
data/releases.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Releases
2
2
 
3
+ ## v0.9.0
4
+
5
+ - Add `Protocol::URL::LimitError` for configured processing limits.
6
+
7
+ ## v0.8.0
8
+
9
+ - Use consistent limit naming for form data parser constraints.
10
+
3
11
  ## v0.7.0
4
12
 
5
13
  - 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.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -45,6 +45,7 @@ files:
45
45
  - lib/protocol/url.rb
46
46
  - lib/protocol/url/absolute.rb
47
47
  - lib/protocol/url/encoding.rb
48
+ - lib/protocol/url/error.rb
48
49
  - lib/protocol/url/form_data/nested.rb
49
50
  - lib/protocol/url/form_data/parser.rb
50
51
  - lib/protocol/url/path.rb
metadata.gz.sig CHANGED
Binary file