New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 798030 link

Starred by 9 users

Issue metadata

Status: Fixed
Owner: ----
Closed: Jun 2018
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux
Pri: 2
Type: Bug



Sign in to add a comment

'\n' is replaced by '\r\n' when a string is put into a `FormData`

Reported by jason.be...@gmail.com, Dec 29 2017

Issue description

UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36

Steps to reproduce the problem:
Set things up with this JavaScript code:

```
var str = "apples\noranges";
var fd  = new FormData();
fd.set('fruit', str);
```

then, each of these lines *should* evaluate to `true`:

```
fd.get('fruit').length == str.length;
fd.get('fruit').indexOf('\r') == -1;

```

But, in Chromium, both are `false`.

What is the expected behavior?

What went wrong?
A carriage return (`\r`) is placed before every newline character (`\n`) when a string is put into a `FormData`.

Did this work before? N/A 

Does this work in other browsers? Yes

Chrome version: 63.0.3239.108  Channel: stable
OS Version: Linux Mint 18.3
Flash Version:
 
Cc: vamshi.k...@techmahindra.com
Labels: Needs-Feedback Triaged-ET Needs-Triage-M63
@Reporter: Could you please provide a sample test file/URL which would help ET team to triage the issue in a better way.

Thanks!
A test file can be found attached to this e-mail.

That said, I looked at the source code, and it seems that the 
troublesome line is line 211 of 'FormData.cpp' 
<https://cs.chromium.org/chromium/src/third_party/WebKit/Source/core/html/forms/FormData.cpp?l=211>.  
Here, `NormalizeLineEndingstoCRLF` is being called.  It seems to me that 
probably nothing should be called to change the contents of the string.  
I think that, no matter how you try to normalize the line endings, 
you're going to end up changing the string in ways that are surprising 
to people (and were surprising to me, when I sent a string through 
`FormData`, got it back from the server, and puzzled over trying to 
figure out why it didn't have identity with the one that I sent).  I 
would think it's better just to leave them alone.  This is what Firefox 
seems to be doing, at least with regards to CR and LF.

If we agree that this is a bug and have a clear idea of what the 
solution is, I'm happy to implement and submit the fix, myself.

On 12/29/2017 6:00 AM, vamshi.k… via monorail wrote:
Project Member

Comment 3 by sheriffbot@chromium.org, Dec 29 2017

Labels: -Needs-Feedback
Thank you for providing more feedback. Adding requester "vamshi.kommuri@techmahindra.com" to the cc list and removing "Needs-Feedback" label.

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
Components: Blink>Forms
Components: Blink>Network>XHR
Status: Available (was: Unconfirmed)
Adding Blink>Network>XHR to the component list, FormData is defined there.

I'm also confirming the bug. I don't see anything about this in the spec, and neither Gecko nor WebKit seem to do this CRLF conversion.

Comment 6 by tkent@chromium.org, May 31 2018

Components: -Blink>Forms Blink>Forms>Submission
Labels: Hotlist-GoodFirstBug
Both of FormData.append() and built-in form control elements use the same append() implementation. We should have two versions; one for FormData.append(), which doesn't normalize string data [1], and another for built-in form controls, which does normalize string data [2].

[1] https://xhr.spec.whatwg.org/#dom-formdata-append
[2] https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#append-an-entry


Owner: hs1217....@samsung.com
Status: Assigned (was: Available)
i will take this issue.

Comment 8 by ratsu...@gmail.com, Jun 7 2018

Hi hs1217@

I'm already working on this and patch was ready, I will upload it later today

And seems both Gecko and Webkit not following the spec do the CRLF convert when appending form control name and value to form data

Comment 9 by ratsu...@gmail.com, Jun 7 2018

If you are not started on this issue (I hope)
Could you let me take it?

Thanks

Comment 10 Deleted

@ratsunny
i started to make patch but i'm fine.
i would like to assign this issue to you instead of me.
but Issue owner must be a project member in this system.
so i can't assign this issue to you.
anyway i will quit to make patch.
please keep doing.
Project Member

Comment 12 by bugdroid1@chromium.org, Jun 13 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/38968451310754c3481dc465631ca3988554497a

commit 38968451310754c3481dc465631ca3988554497a
Author: Sunny <ratsunny@gmail.com>
Date: Wed Jun 13 04:51:57 2018

Align FormData CRLF normalization behavior with standards

According to xhr spec[1], no CRLF normalize operation need to be
performed when invoking FormData methods, so all normalization
call is removed in this commit.

But in form sepc[2], when appending data from form controls to
FormData, both name and value should be normalized. New methods
|FormData::AppendFromElement| will perform the normalize operation.

[1] https://xhr.spec.whatwg.org/#dom-formdata-append
[2] https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#append-an-entry

BUG= 798030 

Change-Id: If90a8e500705013c2935e5290624d4414dd32a72
Reviewed-on: https://chromium-review.googlesource.com/1091238
Reviewed-by: Kent Tamura <tkent@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#566723}
[modify] https://crrev.com/38968451310754c3481dc465631ca3988554497a/third_party/WebKit/LayoutTests/http/tests/local/formdata/formdata-methods.html
[modify] https://crrev.com/38968451310754c3481dc465631ca3988554497a/third_party/blink/renderer/core/html/forms/base_checkable_input_type.cc
[modify] https://crrev.com/38968451310754c3481dc465631ca3988554497a/third_party/blink/renderer/core/html/forms/file_input_type.cc
[modify] https://crrev.com/38968451310754c3481dc465631ca3988554497a/third_party/blink/renderer/core/html/forms/form_data.cc
[modify] https://crrev.com/38968451310754c3481dc465631ca3988554497a/third_party/blink/renderer/core/html/forms/form_data.h
[modify] https://crrev.com/38968451310754c3481dc465631ca3988554497a/third_party/blink/renderer/core/html/forms/form_data_test.cc
[modify] https://crrev.com/38968451310754c3481dc465631ca3988554497a/third_party/blink/renderer/core/html/forms/hidden_input_type.cc
[modify] https://crrev.com/38968451310754c3481dc465631ca3988554497a/third_party/blink/renderer/core/html/forms/html_button_element.cc
[modify] https://crrev.com/38968451310754c3481dc465631ca3988554497a/third_party/blink/renderer/core/html/forms/html_select_element.cc
[modify] https://crrev.com/38968451310754c3481dc465631ca3988554497a/third_party/blink/renderer/core/html/forms/html_text_area_element.cc
[modify] https://crrev.com/38968451310754c3481dc465631ca3988554497a/third_party/blink/renderer/core/html/forms/image_input_type.cc
[modify] https://crrev.com/38968451310754c3481dc465631ca3988554497a/third_party/blink/renderer/core/html/forms/input_type.cc
[modify] https://crrev.com/38968451310754c3481dc465631ca3988554497a/third_party/blink/renderer/core/html/forms/submit_input_type.cc
[modify] https://crrev.com/38968451310754c3481dc465631ca3988554497a/third_party/blink/renderer/core/html/forms/text_field_input_type.cc

Comment 13 by ratsu...@gmail.com, Jun 13 2018

A great thanks to @hs1217 and @tkent
I believe this issue could marked as "Fixed" now

Comment 14 by tkent@chromium.org, Jun 13 2018

Labels: -Triaged-ET Target-69
Status: Fixed (was: Assigned)

Sign in to add a comment