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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/protocol/url/form_data/nested.rb +7 -7
- data/lib/protocol/url/form_data/parser.rb +20 -20
- data/lib/protocol/url/version.rb +1 -1
- data/readme.md +4 -0
- data/releases.md +4 -0
- data.tar.gz.sig +0 -0
- metadata +1 -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: 0e251b8fa72bc3017a56cfa385bf2bc7b9e1e4ef8add2bcd12fb8321cc349c75
|
|
4
|
+
data.tar.gz: 700835c1db54aead624eb89003c7daa42d9ad992f7139c336e2a5293291db619
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
14
|
-
|
|
13
|
+
# The bracketed form name depth limit.
|
|
14
|
+
DEPTH_LIMIT = 8
|
|
15
15
|
|
|
16
16
|
# Initialize the nested form data.
|
|
17
|
-
# @parameter
|
|
18
|
-
def initialize(
|
|
19
|
-
@
|
|
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 @
|
|
35
|
-
raise RangeError, "Form data depth exceeded limit of #{@
|
|
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
|
|
17
|
-
|
|
16
|
+
# The encoded body size limit.
|
|
17
|
+
SIZE_LIMIT = 2 * 1024 * 1024
|
|
18
18
|
|
|
19
|
-
# The
|
|
20
|
-
|
|
19
|
+
# The form pair count limit.
|
|
20
|
+
PAIR_COUNT_LIMIT = 1024
|
|
21
21
|
|
|
22
22
|
# Initialize the form data parser.
|
|
23
|
-
# @parameter
|
|
24
|
-
# @parameter
|
|
25
|
-
# @parameter
|
|
26
|
-
def initialize(
|
|
27
|
-
@
|
|
28
|
-
@
|
|
29
|
-
@
|
|
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
|
-
|
|
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
|
-
|
|
64
|
-
check_limit(:
|
|
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, @
|
|
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, @
|
|
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(
|
|
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,
|
|
109
|
-
if
|
|
110
|
-
raise RangeError, "Form data #{name} exceeded limit of #{
|
|
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
|
data/lib/protocol/url/version.rb
CHANGED
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
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
|
Binary file
|