Skip to content

FormHttpMessageConverter should use configured charset (by default UTF-8) for "text-plain" MIME part conversion as well [SPR-14338] #18910

Closed
@spring-projects-issues

Description

@spring-projects-issues

Rafał Garbowski opened SPR-14338 and commented

Problem:
By default "FormHttpMessageConverter" encodes "text/plain" parts of "MULTIPART_FORM_DATA" message in "latin-1" charset, so eastern european characters are not supported.

Here is example, where I want to send value "łęąć".
How it works now:

    --CJRdVETZo8EZUnHRNhUAkJxwfgiaRlH
    Content-Disposition: form-data; name="param"
    Content-Type: text/plain;charset=ISO-8859-1
    Content-Length: 4

    ????
    --CJRdVETZo8EZUnHRNhUAkJxwfgiaRlH--

And how it should work:

    --QHVM39WsZleGp9jW4RYYKzO7OcqwMpQZRpaQcS7
    Content-Disposition: form-data; name="param"
    Content-Type: text/plain;charset=UTF-8
    Content-Length: 8

    łęąć
    --QHVM39WsZleGp9jW4RYYKzO7OcqwMpQZRpaQcS7--

Now workaround is defining all default converters once again in some configuration bean, setting UTF-8 to "StringHttpMessageConverter" and then putting back as argument of method "setPartConverters".

formConverter.setPartConverters(Arrays.asList(new ByteArrayHttpMessageConverter(), new StringHttpMessageConverter(Charsets.UTF_8), new ResourceHttpMessageConverter()));

Why not use UTF-8 by default to encode "plain/text" MIME parts? Here is link to "pull-request" of this solution on GitHub:
3cdda3a

In multipart/form-data specs I didn't find a word about preferable encoding.
In our case "FormHttpMessageConverter" is forcing "ISO-8859-1" charset. It isn't the same as not defining it at all and allowing recipient to use default - see this answer on stackoverflow. So FIX presented on Github shouldn't crash old systems. Is there any application that accepts only "latin-1" encoded requests? I don't think so.


Reference URL: #1072

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