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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/protocol/url/error.rb +12 -0
- data/lib/protocol/url/form_data/nested.rb +8 -7
- data/lib/protocol/url/form_data/parser.rb +21 -20
- data/lib/protocol/url/version.rb +1 -1
- data/lib/protocol/url.rb +1 -0
- data/readme.md +8 -0
- data/releases.md +8 -0
- data.tar.gz.sig +0 -0
- metadata +2 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 251219144c71f40dba05ef7ad726a20b17c94beb55733317a9378e000528575b
|
|
4
|
+
data.tar.gz: 81be14b9dd98770859406b28a658604ea356791173c4d352d52487735364dafe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 48b8dcae7d84dacf3bb49ce45b84d308dd2c7f0377b97e84f4d9530d4a2467d04b16a76186b3859c8fc3052da50117b197dc6a5ebc503a2568126255c234c43c
|
|
7
|
+
data.tar.gz: 85c632aa585bec3155f294becdee9e904b8f424bab0ef95944c15e563c7e6a5ec2a26ad8a0941ad198ce50a65fec43c84187f76dc596c6dc4bbbd879dcef7b8d
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
|
@@ -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
|
|
14
|
-
|
|
14
|
+
# The bracketed form name depth limit.
|
|
15
|
+
DEPTH_LIMIT = 8
|
|
15
16
|
|
|
16
17
|
# Initialize the nested form data.
|
|
17
|
-
# @parameter
|
|
18
|
-
def initialize(
|
|
19
|
-
@
|
|
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 @
|
|
35
|
-
raise
|
|
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
|
|
17
|
-
|
|
17
|
+
# The encoded body size limit.
|
|
18
|
+
SIZE_LIMIT = 2 * 1024 * 1024
|
|
18
19
|
|
|
19
|
-
# The
|
|
20
|
-
|
|
20
|
+
# The form pair count limit.
|
|
21
|
+
PAIR_COUNT_LIMIT = 1024
|
|
21
22
|
|
|
22
23
|
# Initialize the form data parser.
|
|
23
|
-
# @parameter
|
|
24
|
-
# @parameter
|
|
25
|
-
# @parameter
|
|
26
|
-
def initialize(
|
|
27
|
-
@
|
|
28
|
-
@
|
|
29
|
-
@
|
|
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
|
-
|
|
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
|
-
|
|
64
|
-
check_limit(:
|
|
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, @
|
|
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, @
|
|
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(
|
|
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,
|
|
109
|
-
if
|
|
110
|
-
raise
|
|
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
|
data/lib/protocol/url/version.rb
CHANGED
data/lib/protocol/url.rb
CHANGED
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.
|
|
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
|