protocol-url 0.6.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 +1 -1
- data/lib/protocol/url/form_data/nested.rb +7 -7
- data/lib/protocol/url/form_data/parser.rb +27 -24
- data/lib/protocol/url/version.rb +1 -1
- data/readme.md +8 -0
- data/releases.md +8 -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
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
K"�7z<\�m.zQѕ8�cEw��F)?f}��؋> x��h;I��a�����V�5�n>�\Cfq��'A�)������ܕ��J��$h�W�?�X���&X�T�Nc��9���O�C�,�@���y�Q�n�'�QR�H�iC���I�ͬ��U����F�fI�Fk��5��V\�ofO��0���F�)&_�uKr�d��� щ�?wt�7�������<,���c�Ҭ�ܷ��|�\��?ҍ���c��b@Qk�o��,�$�����)\�r�O�_�s���ĭ84���co�QyA�r31�iR&8�����sg�a�kp��_�'� +��R����.X�\пD�@�p�c&�0#��C�lm?��+��ܜ�va��CD�
|
|
@@ -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.
|
|
@@ -34,17 +34,16 @@ module Protocol
|
|
|
34
34
|
# When a block is given, each decoded value is passed through the block before assignment. The value returned by the block is assigned to the result.
|
|
35
35
|
#
|
|
36
36
|
# @parameter body [Object] A readable body which yields chunks from `#read`.
|
|
37
|
+
# @parameter result [Object] The result to populate. It must support `#add` and `#to_h`.
|
|
37
38
|
# @yields {|name, value| ...} Each decoded form pair before assignment.
|
|
38
39
|
# @returns [Hash] The nested form data.
|
|
39
|
-
def parse(body)
|
|
40
|
-
nested = Nested.new(maximum_depth: @maximum_depth)
|
|
41
|
-
|
|
40
|
+
def parse(body, result = make_result)
|
|
42
41
|
each(body) do |name, value|
|
|
43
42
|
value = yield(name, value) if block_given?
|
|
44
|
-
|
|
43
|
+
result.add(name, value)
|
|
45
44
|
end
|
|
46
45
|
|
|
47
|
-
return
|
|
46
|
+
return result.to_h
|
|
48
47
|
end
|
|
49
48
|
|
|
50
49
|
# Incrementally enumerate URL-encoded form data as ordered name/value pairs.
|
|
@@ -55,14 +54,14 @@ module Protocol
|
|
|
55
54
|
return to_enum(__method__, body) unless block_given?
|
|
56
55
|
|
|
57
56
|
buffer = String.new.b
|
|
58
|
-
|
|
57
|
+
size = 0
|
|
59
58
|
pair_count = 0
|
|
60
59
|
|
|
61
60
|
while chunk = body.read
|
|
62
61
|
break if chunk.empty?
|
|
63
62
|
|
|
64
|
-
|
|
65
|
-
check_limit(:
|
|
63
|
+
size += chunk.bytesize
|
|
64
|
+
check_limit(:size, size, @size_limit)
|
|
66
65
|
buffer << chunk
|
|
67
66
|
|
|
68
67
|
while separator = buffer.index("&")
|
|
@@ -71,7 +70,7 @@ module Protocol
|
|
|
71
70
|
|
|
72
71
|
unless assignment.empty?
|
|
73
72
|
pair_count += 1
|
|
74
|
-
check_limit(:pair_count, pair_count, @
|
|
73
|
+
check_limit(:pair_count, pair_count, @pair_count_limit)
|
|
75
74
|
yield_pair(assignment) {|name, value| yield name, value}
|
|
76
75
|
end
|
|
77
76
|
end
|
|
@@ -79,7 +78,7 @@ module Protocol
|
|
|
79
78
|
|
|
80
79
|
unless buffer.empty?
|
|
81
80
|
pair_count += 1
|
|
82
|
-
check_limit(:pair_count, pair_count, @
|
|
81
|
+
check_limit(:pair_count, pair_count, @pair_count_limit)
|
|
83
82
|
yield_pair(buffer) {|name, value| yield name, value}
|
|
84
83
|
end
|
|
85
84
|
|
|
@@ -88,6 +87,10 @@ module Protocol
|
|
|
88
87
|
|
|
89
88
|
private
|
|
90
89
|
|
|
90
|
+
def make_result
|
|
91
|
+
return Nested.new(depth_limit: @depth_limit)
|
|
92
|
+
end
|
|
93
|
+
|
|
91
94
|
def yield_pair(assignment)
|
|
92
95
|
name, value = assignment.split("=", 2)
|
|
93
96
|
|
|
@@ -102,9 +105,9 @@ module Protocol
|
|
|
102
105
|
return Encoding.unescape(component.tr("+", " "))
|
|
103
106
|
end
|
|
104
107
|
|
|
105
|
-
def check_limit(name, value,
|
|
106
|
-
if
|
|
107
|
-
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}!"
|
|
108
111
|
end
|
|
109
112
|
end
|
|
110
113
|
end
|
data/lib/protocol/url/version.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.8.0
|
|
38
|
+
|
|
39
|
+
- Use consistent limit naming for form data parser constraints.
|
|
40
|
+
|
|
41
|
+
### v0.7.0
|
|
42
|
+
|
|
43
|
+
- Allow `Protocol::URL::FormData::Parser#parse` to populate a supplied result object.
|
|
44
|
+
|
|
37
45
|
### v0.6.0
|
|
38
46
|
|
|
39
47
|
- Add `Protocol::URL::FormData::Parser` for incremental, limited parsing of `application/x-www-form-urlencoded` form data.
|
data/releases.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Releases
|
|
2
2
|
|
|
3
|
+
## v0.8.0
|
|
4
|
+
|
|
5
|
+
- Use consistent limit naming for form data parser constraints.
|
|
6
|
+
|
|
7
|
+
## v0.7.0
|
|
8
|
+
|
|
9
|
+
- Allow `Protocol::URL::FormData::Parser#parse` to populate a supplied result object.
|
|
10
|
+
|
|
3
11
|
## v0.6.0
|
|
4
12
|
|
|
5
13
|
- Add `Protocol::URL::FormData::Parser` for incremental, limited parsing of `application/x-www-form-urlencoded` form data.
|
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
|
Binary file
|