\n become \r\n in formdata
Categories
(Core :: DOM: Networking, defect, P3)
Tracking
()
Tracking | Status | |
---|---|---|
firefox78 | --- | affected |
People
(Reporter: reallyimeric, Unassigned)
References
(Depends on 1 open bug)
Details
(Whiteboard: [necko-triaged])
Attachments
(1 file)
896 bytes,
application/x-zip-compressed
|
Details |
User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0
Steps to reproduce:
fd = new FormData
fd.append('k', 'A\nA')
fetch('/', {method: 'POST', body: fd})
Actual results:
firefox send 'A\r\nA' as the value of key 'k'
Expected results:
firefox send 'A\nA' as the value of key 'k'
Comment 1•4 years ago
•
|
||
This issue is not detailed enough for me to reproduce it. Issues that address the same issue are set to this component. A developer from this component should understand exactly what it means.
Please attach a test case or some more detailed information on how to properly reproduce it if it needs confirmation or verification. Thank you!
Reporter | ||
Comment 2•4 years ago
|
||
- use any network monitor (e.g., wireshark) to inspect http traffic
- send a multipart/formdata POST request at any http site, using dev tool console:
fd = new FormData
fd.append('k', 'A\nA')
fetch('/', {method: 'POST', body: fd})
wireshark shows firefox send 41 0d 0a 41
(that is A\r\nA
in utf-8 hex) instead of 41 0a 41
Comment 3•4 years ago
|
||
I can repro this and am attaching Node.js server script:
- Run the script
- Access https://localhost:5000/
- See the result
Comment 5•4 years ago
|
||
John, I want to say this is working as expected but don't know that much about FormData so wanted to check with you, who from commits seem to be more familiar with this area.
Comment 6•4 years ago
•
|
||
The FormData appends follows the spec[1], however, the problem may in the fetch request which uses line break converting while constructing fetch request. While constructing a fetch request[2], it will run ExtractByteStreamFromBody
[3] then GetSendInfo
[4] will use FSMultipartFormData
[5] to get form data which will do line break converting[5] at the same time. I also test that Safari and Firefox has the same issue, but Chrome didn't.
[1] https://xhr.spec.whatwg.org/#dom-formdata-append and https://searchfox.org/mozilla-central/rev/cf561cece0ca9aeaf0202e68699836d957d0c670/dom/base/FormData.h#108
[2] https://searchfox.org/mozilla-central/rev/227f22acef5c4865503bde9f835452bf38332c8e/dom/fetch/Request.cpp#583
[3] https://searchfox.org/mozilla-central/rev/227f22acef5c4865503bde9f835452bf38332c8e/dom/fetch/Fetch.cpp#888
[4] https://searchfox.org/mozilla-central/rev/cf561cece0ca9aeaf0202e68699836d957d0c670/dom/base/FormData.cpp#318
[5] https://searchfox.org/mozilla-central/rev/227f22acef5c4865503bde9f835452bf38332c8e/dom/html/HTMLFormSubmission.cpp#391-393
Updated•4 years ago
|
Comment 7•4 years ago
|
||
Hi Michal, per comment 6, this looks more a issue in fetch request code, which per my understanding is within the DOM: Networking module. Can you/your team check again? Thanks.
Updated•4 years ago
|
Comment 8•4 years ago
•
|
||
I wonder if we have the same issue on form submission with enctype="multipart/form-data"
?
Comment 9•4 years ago
|
||
(In reply to Edgar Chen [:edgar] from comment #8)
I wonder if we have the same issue on form submition with
enctype="multipart/form-data"
?
If I read the spec correctly, enctype="multipart/form-data"
is one of submit-body[1], hence, it should follow append an entry
[2] algorithm which is line break normalization while form submitting.
[1] https://html.spec.whatwg.org/#submit-body
[2] https://html.spec.whatwg.org/#append-an-entry
Updated•4 years ago
|
Comment 10•4 years ago
|
||
Hi John,
It seems that you already know where the problem is. Are you willing to take this bug?
Given the current status of necko team, I think no one has time to work on this.
Comment 11•4 years ago
|
||
Sure, I will spend time work on it. Thank you.
Comment 12•4 years ago
|
||
(In reply to John Dai[:jdai] from comment #11)
Sure, I will spend time work on it. Thank you.
Thank you!
Updated•4 years ago
|
Comment 14•4 years ago
|
||
Whether this is a bug or not is now being reconsidered in the spec: https://github.com/whatwg/html/issues/6469
Comment 15•4 years ago
|
||
My bad, I think I read this bug wrong. The issue I linked has nothing to do with the bug. https://github.com/whatwg/html/pull/6287, however, will make Firefox's behavior not a bug.
Updated•4 years ago
|
Description
•