eclipse-ee4j / eclipse-ee4j/jersey
MultipartFeature does not support UTF-8 encoding of Content-disposition header
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
Given an HTML form with utf-8 encoding specified:
```.html
Submit
```
Chrome (and other browsers) will send the following request to the server:
```
Content-type: multipart/form-data; boundary=----WebKitFormBoundaryU6khB3JchXEPIZEA
------WebKitFormBoundaryU6khB3JchXEPIZEA
Content-Disposition: form-data; name="annex"; filename="LETTRE_Transfert de la gestion des données.txt"
Content-Type: text/plain
Bla blah
------WebKitFormBoundaryU6khB3JchXEPIZEA--
```
However, Jersey 3.11 (and 4.0 from what I can tell), will interpret the file name as ISO8859-1 encoded text.
```.java
@POST
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response upload(@FormDataParam("annex") FormDataBodyPart annexFile) throws IOException {
// The following will fail: text will be "LETTRE_Transfert de la gestion des données.txt"
assert annexFile.getFormDataContentDisposition().getFileName().equals("LETTRE_Transfert de la gestion des données.txt);
}
```
This is because the multipart feature relies on the `MIMEParser` class from the [metro-mimepull](https://github.com/eclipse-ee4j/metro-mimepull) library which [hardcodes](https://github.com/eclipse-ee4j/metro-mimepull/blob/cc9d6a2c866e863f432967ce65764296a2255abc/src/main/java/org/jvnet/mimepull/MIMEParser.java#L42) the character encoding of headers as ISO8859-1.
Since browser don't actually send include the character set as a parameter of the `Content-type` header, I think the only solution would be to make this configurable.
If someone on the project can indicate the most appropriate method of configuration, I am happy to submit a pull request to both metro-mimepull and this repo.
Contributor guide
Research direction
Start with Jersey's MultipartFeature and the referenced metro-mimepull MIMEParser.java, focusing on the hardcoded ISO8859-1 header decoding. Reproduce the multipart upload using the UTF-8 filename shown in the issue and trace how getFormDataContentDisposition().getFileName() is produced. Done means the filename is preserved correctly or the encoding can be configured, with behavior covered by a test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100