Generation of multipart post fail if inconsistent encodings given as input
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Start in lib/net/http/generic_request.rb at encode_multipart_form_data and reproduce the supplied mixed UTF-8 and ASCII-8BIT StringIO example. Trace the multipart assembly that raises Encoding::CompatibilityError, then verify that a multipart request containing differently encoded inputs can be generated and sent without that failure.
Written by the indexing model from the issue text.
Description
When attaching multipart entities of different encodings it is easy to get failures due to intermediary strings inside encode_multipart_form_data that care about encoding despite there being no need to care about them.
Example:
require "net/http"
require "stringio"
utf_string = "räksmörgås"
ascii_string = "räkmacka"
ascii_string.force_encoding("ASCII-8BIT")
form_data = {
"foo" => "bar",
"utf8" => StringIO.new(utf_string),
"ascii" => StringIO.new(ascii_string)
}
url = URI("http://www.example.com")
request = Net::HTTP::Post.new(url)
request.set_form(form_data, "multipart/form-data")
Net::HTTP.start(url.hostname, url.port) do |http|
http.request(request)
end
This results in
net-http-0.4.1/lib/net/http/generic_request.rb:354:in `block in encode_multipart_form_data': incompatible character encodings: UTF-8 and ASCII-8BIT (Encoding::CompatibilityError)
from /home/linus/.gem/ruby/3.3.3/gems/net-http-0.4.1/lib/net/http/generic_request.rb:320:in `each'
from /home/linus/.gem/ruby/3.3.3/gems/net-http-0.4.1/lib/net/http/generic_request.rb:320:in `encode_multipart_form_data'
from /home/linus/.gem/ruby/3.3.3/gems/net-http-0.4.1/lib/net/http/generic_request.rb:303:in `send_request_with_body_data'
from /home/linus/.gem/ruby/3.3.3/gems/net-http-0.4.1/lib/net/http/generic_request.rb:204:in `exec'
[...]
There are real use cases that are reasonable like posting both a text file and a pdf at the same time.
A workaround is to always encode absolutely everything as ascii-8bit before posting it.
- Dominant language
- Ruby
- Stars
- 148
- Forks
- 95
- Avg merge
- 10h 54m
- Merged PRs (30d)
- 4
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ruby/net-http
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
-
Difficulty 5/5 Over a week Newbie friendliness 38/100
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
Similar issues
-
SyncEm always forwards a dummy block, so wrapped methods lose their no-block/Enumerator behavior Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
endoflife-date/endoflife.date#11086 ·
-
internal
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Kong/developer.konghq.com#7322 ·
-
bug P2
Difficulty 2/5 1-3 hours Newbie friendliness 88/100