http-form_data 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +3 -0
- data/CHANGES.md +12 -0
- data/Gemfile +1 -1
- data/lib/http/form_data/composite_io.rb +6 -4
- data/lib/http/form_data/multipart/param.rb +1 -1
- data/lib/http/form_data/readable.rb +3 -1
- data/lib/http/form_data/version.rb +1 -1
- data/spec/lib/http/form_data/composite_io_spec.rb +21 -0
- data/spec/lib/http/form_data/file_spec.rb +44 -20
- data/spec/lib/http/form_data/multipart_spec.rb +6 -0
- data/spec/lib/http/form_data/part_spec.rb +6 -0
- data/spec/lib/http/form_data/urlencoded_spec.rb +6 -0
- data/spec/spec_helper.rb +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 909d3d6b05b19fec60fcea6016be93adcde0cc4c86e62d918dd47e1dc52580f1
|
4
|
+
data.tar.gz: 55cf57b3b18b038cf4b7641cd56e790f61686e77ff10589c4c2d942685f771b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29b89bd6588b76241ea70d08c919ef70e68acbf8705386a0b4e99532e648cc58df298faaab1982206a7c86c27c8a1e59c28f7e60b3328459bc02f1a79ea66395
|
7
|
+
data.tar.gz: fd703850f29023873d4ecf7026a457e763a33e1cd76c97d67656eb06e6bcaf59f7599066b02d490cf83b2598e4c5e01631cd1cdb9ba2930d6cc61b90922e4b12
|
data/.rubocop.yml
CHANGED
data/CHANGES.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## 2.1.0 (2018-03-05)
|
2
|
+
|
3
|
+
* [#21](https://github.com/httprb/form_data/pull/21)
|
4
|
+
Rewind content at the end of `Readable#to_s`.
|
5
|
+
[@janko-m][]
|
6
|
+
|
7
|
+
* [#19](https://github.com/httprb/form_data/pull/19)
|
8
|
+
Fix buffer encoding.
|
9
|
+
[@HoneyryderChuck][]
|
10
|
+
|
11
|
+
|
1
12
|
## 2.0.0 (2017-10-01)
|
2
13
|
|
3
14
|
* [#17](https://github.com/httprb/form_data/pull/17)
|
@@ -59,3 +70,4 @@
|
|
59
70
|
[@abotalov]: https://github.com/abotalov
|
60
71
|
[@janko-m]: https://github.com/janko-m
|
61
72
|
[@mhickman]: https://github.com/mhickman
|
73
|
+
[@HoneyryderChuck]: https://github.com/HoneyryderChuck
|
data/Gemfile
CHANGED
@@ -9,7 +9,7 @@ module HTTP
|
|
9
9
|
# @param [Array<IO>] ios Array of IO objects
|
10
10
|
def initialize(ios)
|
11
11
|
@index = 0
|
12
|
-
@buffer =
|
12
|
+
@buffer = "".b
|
13
13
|
@ios = ios.map do |io|
|
14
14
|
if io.is_a?(String)
|
15
15
|
StringIO.new(io)
|
@@ -29,14 +29,16 @@ module HTTP
|
|
29
29
|
#
|
30
30
|
# @return [String, nil]
|
31
31
|
def read(length = nil, outbuf = nil)
|
32
|
-
outbuf = outbuf.to_s.
|
32
|
+
outbuf = outbuf.to_s.clear
|
33
|
+
# buffer in JRuby is sometimes US-ASCII, force to ASCII-8BIT
|
34
|
+
outbuf.force_encoding(Encoding::BINARY)
|
33
35
|
|
34
36
|
while current_io
|
35
37
|
current_io.read(length, @buffer)
|
36
|
-
outbuf << @buffer
|
38
|
+
outbuf << @buffer.force_encoding(Encoding::BINARY)
|
37
39
|
|
38
40
|
if length
|
39
|
-
length -= @buffer.
|
41
|
+
length -= @buffer.bytesize
|
40
42
|
break if length.zero?
|
41
43
|
end
|
42
44
|
|
@@ -65,6 +65,27 @@ RSpec.describe HTTP::FormData::CompositeIO do
|
|
65
65
|
expect(composite_io.read(3, outbuf)).to eq nil
|
66
66
|
expect(outbuf).to eq ""
|
67
67
|
end
|
68
|
+
|
69
|
+
it "returns data in binary encoding" do
|
70
|
+
io = HTTP::FormData::CompositeIO.new(%w[Janko Marohnić])
|
71
|
+
|
72
|
+
expect(io.read(5).encoding).to eq Encoding::BINARY
|
73
|
+
expect(io.read(9).encoding).to eq Encoding::BINARY
|
74
|
+
|
75
|
+
io.rewind
|
76
|
+
expect(io.read.encoding).to eq Encoding::BINARY
|
77
|
+
expect(io.read.encoding).to eq Encoding::BINARY
|
78
|
+
end
|
79
|
+
|
80
|
+
it "reads data in bytes" do
|
81
|
+
emoji = "😃"
|
82
|
+
io = HTTP::FormData::CompositeIO.new([emoji])
|
83
|
+
|
84
|
+
expect(io.read(1)).to eq emoji.b[0]
|
85
|
+
expect(io.read(1)).to eq emoji.b[1]
|
86
|
+
expect(io.read(1)).to eq emoji.b[2]
|
87
|
+
expect(io.read(1)).to eq emoji.b[3]
|
88
|
+
end
|
68
89
|
end
|
69
90
|
|
70
91
|
describe "#rewind" do
|
@@ -2,10 +2,11 @@
|
|
2
2
|
# coding: utf-8
|
3
3
|
|
4
4
|
RSpec.describe HTTP::FormData::File do
|
5
|
-
let(:opts)
|
5
|
+
let(:opts) { nil }
|
6
|
+
let(:form_file) { described_class.new(file, opts) }
|
6
7
|
|
7
8
|
describe "#size" do
|
8
|
-
subject {
|
9
|
+
subject { form_file.size }
|
9
10
|
|
10
11
|
context "when file given as a String" do
|
11
12
|
let(:file) { fixture("the-http-gem.info").to_s }
|
@@ -30,32 +31,56 @@ RSpec.describe HTTP::FormData::File do
|
|
30
31
|
end
|
31
32
|
|
32
33
|
describe "#to_s" do
|
33
|
-
subject {
|
34
|
+
subject { form_file.to_s }
|
34
35
|
|
35
36
|
context "when file given as a String" do
|
36
37
|
let(:file) { fixture("the-http-gem.info").to_s }
|
37
38
|
it { is_expected.to eq fixture("the-http-gem.info").read(:mode => "rb") }
|
39
|
+
|
40
|
+
it "rewinds content" do
|
41
|
+
content = form_file.read
|
42
|
+
expect(form_file.to_s).to eq content
|
43
|
+
expect(form_file.read).to eq content
|
44
|
+
end
|
38
45
|
end
|
39
46
|
|
40
47
|
context "when file given as a Pathname" do
|
41
48
|
let(:file) { fixture("the-http-gem.info") }
|
42
49
|
it { is_expected.to eq fixture("the-http-gem.info").read(:mode => "rb") }
|
50
|
+
|
51
|
+
it "rewinds content" do
|
52
|
+
content = form_file.read
|
53
|
+
expect(form_file.to_s).to eq content
|
54
|
+
expect(form_file.read).to eq content
|
55
|
+
end
|
43
56
|
end
|
44
57
|
|
45
58
|
context "when file given as File" do
|
46
59
|
let(:file) { fixture("the-http-gem.info").open("rb") }
|
47
60
|
after { file.close }
|
48
61
|
it { is_expected.to eq fixture("the-http-gem.info").read(:mode => "rb") }
|
62
|
+
|
63
|
+
it "rewinds content" do
|
64
|
+
content = form_file.read
|
65
|
+
expect(form_file.to_s).to eq content
|
66
|
+
expect(form_file.read).to eq content
|
67
|
+
end
|
49
68
|
end
|
50
69
|
|
51
70
|
context "when file given as IO" do
|
52
71
|
let(:file) { StringIO.new "привет мир!" }
|
53
72
|
it { is_expected.to eq "привет мир!" }
|
73
|
+
|
74
|
+
it "rewinds content" do
|
75
|
+
content = form_file.read
|
76
|
+
expect(form_file.to_s).to eq content
|
77
|
+
expect(form_file.read).to eq content
|
78
|
+
end
|
54
79
|
end
|
55
80
|
end
|
56
81
|
|
57
82
|
describe "#read" do
|
58
|
-
subject {
|
83
|
+
subject { form_file.read }
|
59
84
|
|
60
85
|
context "when file given as a String" do
|
61
86
|
let(:file) { fixture("the-http-gem.info").to_s }
|
@@ -80,15 +105,13 @@ RSpec.describe HTTP::FormData::File do
|
|
80
105
|
end
|
81
106
|
|
82
107
|
describe "#rewind" do
|
83
|
-
subject { described_class.new(file, opts) }
|
84
|
-
|
85
108
|
context "when file given as a String" do
|
86
109
|
let(:file) { fixture("the-http-gem.info").to_s }
|
87
110
|
|
88
111
|
it "rewinds the underlying IO object" do
|
89
|
-
content =
|
90
|
-
|
91
|
-
expect(
|
112
|
+
content = form_file.read
|
113
|
+
form_file.rewind
|
114
|
+
expect(form_file.read).to eq content
|
92
115
|
end
|
93
116
|
end
|
94
117
|
|
@@ -96,9 +119,9 @@ RSpec.describe HTTP::FormData::File do
|
|
96
119
|
let(:file) { fixture("the-http-gem.info") }
|
97
120
|
|
98
121
|
it "rewinds the underlying IO object" do
|
99
|
-
content =
|
100
|
-
|
101
|
-
expect(
|
122
|
+
content = form_file.read
|
123
|
+
form_file.rewind
|
124
|
+
expect(form_file.read).to eq content
|
102
125
|
end
|
103
126
|
end
|
104
127
|
|
@@ -107,9 +130,9 @@ RSpec.describe HTTP::FormData::File do
|
|
107
130
|
after { file.close }
|
108
131
|
|
109
132
|
it "rewinds the underlying IO object" do
|
110
|
-
content =
|
111
|
-
|
112
|
-
expect(
|
133
|
+
content = form_file.read
|
134
|
+
form_file.rewind
|
135
|
+
expect(form_file.read).to eq content
|
113
136
|
end
|
114
137
|
end
|
115
138
|
|
@@ -117,15 +140,15 @@ RSpec.describe HTTP::FormData::File do
|
|
117
140
|
let(:file) { StringIO.new "привет мир!" }
|
118
141
|
|
119
142
|
it "rewinds the underlying IO object" do
|
120
|
-
content =
|
121
|
-
|
122
|
-
expect(
|
143
|
+
content = form_file.read
|
144
|
+
form_file.rewind
|
145
|
+
expect(form_file.read).to eq content
|
123
146
|
end
|
124
147
|
end
|
125
148
|
end
|
126
149
|
|
127
150
|
describe "#filename" do
|
128
|
-
subject {
|
151
|
+
subject { form_file.filename }
|
129
152
|
|
130
153
|
context "when file given as a String" do
|
131
154
|
let(:file) { fixture("the-http-gem.info").to_s }
|
@@ -174,7 +197,8 @@ RSpec.describe HTTP::FormData::File do
|
|
174
197
|
end
|
175
198
|
|
176
199
|
describe "#content_type" do
|
177
|
-
|
200
|
+
let(:file) { StringIO.new }
|
201
|
+
subject { form_file.content_type }
|
178
202
|
|
179
203
|
it { is_expected.to eq "application/octet-stream" }
|
180
204
|
|
@@ -30,6 +30,12 @@ RSpec.describe HTTP::FormData::Multipart do
|
|
30
30
|
].join("")
|
31
31
|
end
|
32
32
|
|
33
|
+
it "rewinds content" do
|
34
|
+
content = form_data.read
|
35
|
+
expect(form_data.to_s).to eq content
|
36
|
+
expect(form_data.read).to eq content
|
37
|
+
end
|
38
|
+
|
33
39
|
context "with user-defined boundary" do
|
34
40
|
subject(:form_data) do
|
35
41
|
HTTP::FormData::Multipart.new params, :boundary => "my-boundary"
|
@@ -20,6 +20,12 @@ RSpec.describe HTTP::FormData::Part do
|
|
20
20
|
context "when body given as String" do
|
21
21
|
let(:body) { "привет мир!" }
|
22
22
|
it { is_expected.to eq "привет мир!" }
|
23
|
+
|
24
|
+
it "rewinds content" do
|
25
|
+
content = part.read
|
26
|
+
expect(part.to_s).to eq content
|
27
|
+
expect(part.read).to eq content
|
28
|
+
end
|
23
29
|
end
|
24
30
|
end
|
25
31
|
|
@@ -28,6 +28,12 @@ RSpec.describe HTTP::FormData::Urlencoded do
|
|
28
28
|
let(:data) { { "foo[bar]" => "тест" } }
|
29
29
|
it { is_expected.to eq "foo%5Bbar%5D=%D1%82%D0%B5%D1%81%D1%82" }
|
30
30
|
end
|
31
|
+
|
32
|
+
it "rewinds content" do
|
33
|
+
content = form_data.read
|
34
|
+
expect(form_data.to_s).to eq content
|
35
|
+
expect(form_data.read).to eq content
|
36
|
+
end
|
31
37
|
end
|
32
38
|
|
33
39
|
describe "#size" do
|
data/spec/spec_helper.rb
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
require "simplecov"
|
4
4
|
require "coveralls"
|
5
5
|
|
6
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
6
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
|
7
7
|
SimpleCov::Formatter::HTMLFormatter,
|
8
8
|
Coveralls::SimpleCov::Formatter
|
9
|
-
]
|
9
|
+
])
|
10
10
|
|
11
11
|
SimpleCov.start { add_filter "/spec/" }
|
12
12
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http-form_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksey V Zapparov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -84,10 +84,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
86
|
rubyforge_project:
|
87
|
-
rubygems_version: 2.
|
87
|
+
rubygems_version: 2.7.1
|
88
88
|
signing_key:
|
89
89
|
specification_version: 4
|
90
|
-
summary: http-form_data-2.
|
90
|
+
summary: http-form_data-2.1.0
|
91
91
|
test_files:
|
92
92
|
- spec/fixtures/expected-multipart-body.tpl
|
93
93
|
- spec/fixtures/the-http-gem.info
|