Skip to content

script: Encode field names and filenames correctly when encoding <form> data - #44943

Merged
yezhizhen merged 4 commits into
servo:mainfrom
yezhizhen:send-file-form-controls
May 15, 2026
Merged

yezhizhen merged 4 commits into
servo:mainfrom
yezhizhen:send-file-form-controls

Conversation

@yezhizhen

@yezhizhen yezhizhen commented May 15, 2026 •

Copy link
Copy Markdown
Member

Spec

  1. Escape field name for non-file field correctly. Escape both field name and filenames for field field correctly.
  2. Fixed a corner case bug in step 1 implementation.

Testing: Many new passing in existing WPT. I was still following the FileAPI, but somehow the fix is about form data. The tests should probably be moved to forms folder. But that should probably be discussed in upstream.

Part of #10778

yezhizhen added 3 commits May 15, 2026 12:44
Signed-off-by: Euclid Ye <[email protected]>
Signed-off-by: Euclid Ye <[email protected]>
Signed-off-by: Euclid Ye <[email protected]>
@yezhizhen
yezhizhen requested a review from xiaochengh May 15, 2026 05:04
[Newline normalization - \\n in name (formdata)]
expected: FAIL

[Newline normalization - \\r in name (urlencoded)]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we have the same problem for urlencoded form. Checking this later.

// This character isn't LF but is
// preceded by CR
_ if prev == '\r' => {
buf.push('\r');

@yezhizhen yezhizhen May 15, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was buggy before. For example, \rA would generate \r\r\nA previously. New passing.

@yezhizhen
yezhizhen marked this pull request as ready for review May 15, 2026 05:35
@yezhizhen
yezhizhen requested a review from gterzian as a code owner May 15, 2026 05:35
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label May 15, 2026
fn escape_for_header(s: &DOMString) -> String {
s.str()
.replace('\r', "%0D")
.replace('\n', "%0A")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ultra-nit: the order is different here than what's written in the spec

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label May 15, 2026
Signed-off-by: Euclid Ye <[email protected]>
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label May 15, 2026
@yezhizhen
yezhizhen enabled auto-merge May 15, 2026 07:10
@yezhizhen
yezhizhen added this pull request to the merge queue May 15, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label May 15, 2026
Merged via the queue into servo:main with commit 590d22c May 15, 2026
33 checks passed
@yezhizhen
yezhizhen deleted the send-file-form-controls branch May 15, 2026 09:26
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label May 15, 2026
alice pushed a commit to alice/servo that referenced this pull request May 15, 2026
…rm>` data (servo#44943)

[Spec](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart/form-data-encoding-algorithm)

1. Escape field name for non-file field correctly. Escape both field
name and filenames for field field correctly.
2. Fixed a corner case bug in step 1 implementation.

Testing: Many new passing in existing WPT. I was still following the
FileAPI, but somehow the fix is about form data. The tests should
probably be moved to `forms` folder. But that should probably be
discussed in upstream.

Part of servo#10778

---------

Signed-off-by: Euclid Ye <[email protected]>
pull Bot pushed a commit to A-Archives-and-Forks/servo that referenced this pull request May 16, 2026
…ed `<form>` POST (servo#44953)

[Spec](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fs-enctype-urlencoded)
for submit entity body (POST) for x-www-form-urlencoded.

We also extract inner fn `clean_crlf` to `normalize_crlf` as this is
widely common.
Follow up of servo#44943.

Testing: Passing in existing tests.
Part of servo#10778. (Well this isn't
FileAPI, but that's what led me here.)

---------

Signed-off-by: Euclid Ye <[email protected]>
jschwe pushed a commit to jschwe/servo that referenced this pull request Jun 26, 2026
…rm>` data (servo#44943)

[Spec](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart/form-data-encoding-algorithm)

1. Escape field name for non-file field correctly. Escape both field
name and filenames for field field correctly.
2. Fixed a corner case bug in step 1 implementation.

Testing: Many new passing in existing WPT. I was still following the
FileAPI, but somehow the fix is about form data. The tests should
probably be moved to `forms` folder. But that should probably be
discussed in upstream.

Part of servo#10778

---------

Signed-off-by: Euclid Ye <[email protected]>
(cherry picked from commit 590d22c)
jschwe pushed a commit that referenced this pull request Jun 26, 2026
…rm>` data (#44943)

[Spec](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart/form-data-encoding-algorithm)

1. Escape field name for non-file field correctly. Escape both field
name and filenames for field field correctly.
2. Fixed a corner case bug in step 1 implementation.

Testing: Many new passing in existing WPT. I was still following the
FileAPI, but somehow the fix is about form data. The tests should
probably be moved to `forms` folder. But that should probably be
discussed in upstream.

Part of #10778

---------

Signed-off-by: Euclid Ye <[email protected]>
(cherry picked from commit 590d22c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-awaiting-review There is new code that needs to be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants