Skip to content

script: Encode with requested encoding for <form enctype="multipart/form-data"> #45028

Merged
TimvdLippe merged 4 commits into
servo:mainfrom
yezhizhen:form
May 22, 2026
Merged

script: Encode with requested encoding for <form enctype="multipart/form-data"> #45028
TimvdLippe merged 4 commits into
servo:mainfrom
yezhizhen:form

Conversation

@yezhizhen

@yezhizhen yezhizhen commented May 20, 2026

Copy link
Copy Markdown
Member

Encode with requested encoding.

Implement step 2.3 of https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart/form-data-encoding-algorithm:

Field names, field values for non-file fields, and filenames for file fields, in the generated multipart/form-data resource must be set to the result of encoding the corresponding entry's name or value with encoding, converted to a byte sequence.

Testing: Existing wpt.
Part of #10778

yezhizhen added 2 commits May 20, 2026 18:05
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
@yezhizhen
yezhizhen requested a review from xiaochengh May 20, 2026 10:12
@yezhizhen
yezhizhen requested a review from gterzian as a code owner May 20, 2026 10:12
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label May 20, 2026
Comment on lines +1988 to +1989
fn encode_with_html_fallback<'a>(input: &'a str, encoding: &'static Encoding) -> Cow<'a, [u8]> {
encoding.encode(input).0

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.

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>

@TimvdLippe TimvdLippe left a comment

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.

I find the format macros easier to read than multiple .extend calls. I think your fix is mostly related to correct escaping now, which is great. So I think we can use format! and still have your fixes in as well?

result.extend(b"\r\n\r\n");

let mut bytes = f.upcast::<Blob>().get_bytes().unwrap_or(vec![]);
let mut bytes = f.upcast::<Blob>().get_bytes().unwrap_or_else(|_| vec![]);

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.

Nit: I am surprised clippy doesn't want this to be unwrap_or_default()?

Comment thread components/script/dom/html/htmlformelement.rs
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label May 22, 2026
@TimvdLippe
TimvdLippe enabled auto-merge May 22, 2026 10:44
@TimvdLippe
TimvdLippe added this pull request to the merge queue May 22, 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 22, 2026
Merged via the queue into servo:main with commit 5c201b6 May 22, 2026
30 checks passed
@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 22, 2026
@yezhizhen
yezhizhen deleted the form branch May 22, 2026 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants