Skip to content

HttpHeaders.setContentDispositionFormData() doesn't encode non-acsii characters correctly [SPR-14547] #19115

@spring-projects-issues

Description

@spring-projects-issues

Wenhao Ji opened SPR-14547 and commented

When passing name or filename containing non-ascii characters to the setContentDispositionFormData method, a browser like Chrome and IE may behave strangely, opening a download dialog where those characters are replaced by hyphens.

The parameters in http headers should be encoded according to [RFC5987] https://tools.ietf.org/html/rfc5987, so that we can get the correct string no matter what kind of characters are passed into.

For example,

@RequestMapping("downloadForm")
public HttpEntity<String> downloadFormData() throws UnsupportedEncodingException {
    HttpHeaders headers = new HttpHeaders();
    headers.setContentDispositionFormData("form", "中文.txt");
    return new HttpEntity<String>("a=b", headers);
}

The Content-Disposition header values that returns from the controller method above should be like filename=UTF-8'zh-Hant-CN'%E4%B8%AD%E6%96%87.txt.


Affects: 4.3.2

Issue Links:

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions