Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Posted forms are decoded with ISO-8859-1 instead of UTF-8 #3912

Closed
rreitmann opened this issue Sep 7, 2015 · 12 comments
Closed

Posted forms are decoded with ISO-8859-1 instead of UTF-8 #3912

rreitmann opened this issue Sep 7, 2015 · 12 comments
Assignees
Labels
type: bug A general bug type: regression A regression from a previous release
Milestone

Comments

@rreitmann
Copy link

Hi,

after upgrading from 1.3.0.M4 to 1.3.0.M5 form parameter if sent with a POST seem to be decoded with ISO-8859-1 instead of UTF-8. Have there been any changes?

@wilkinsona
Copy link
Member

Not knowingly. Can you share a sample project that reproduces the problem?

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Sep 7, 2015
@rreitmann
Copy link
Author

Our project is public: https://github.com/dzhw/metadatamanagement

You can see the described behavior here https://metadatamanagement.cfapps.io/en/variables/create if you put an 'Ü' in label and submit the form.

@wilkinsona wilkinsona added type: bug A general bug type: regression A regression from a previous release and removed status: waiting-for-feedback We need additional information before we can continue labels Sep 7, 2015
@wilkinsona wilkinsona added this to the 1.3.0.RC1 milestone Sep 7, 2015
@wilkinsona wilkinsona self-assigned this Sep 7, 2015
@wilkinsona
Copy link
Member

Thanks. And thanks, too, to @timtebeek.

Unfortunately, the changes made in 2b3d419 have altered the ordering of the auto-configured filters. In M4 the ordering was:

  • Character encoding filter
  • Hidden HTTP method filter and HTTP put content form filter

In M5 the ordering is:

  • Hidden HTTP method filter
  • HTTP put content form filter
  • Character encoding filter

HiddenHttpMethodFilter accesses the request's parameters so it's vital that it go after CharacterEncodingFilter otherwise the parameters will be read in the wrong encoding.

A workaround is to declare your own OrderedCharacterEncodingFilter bean and ensure that it goes first:

@Autowired
private HttpEncodingProperties httpEncodingProperties;

@Bean
public OrderedCharacterEncodingFilter characterEncodingFilter() {
    OrderedCharacterEncodingFilter filter = new OrderedCharacterEncodingFilter();
    filter.setEncoding(this.httpEncodingProperties.getCharset().name());
    filter.setForceEncoding(this.httpEncodingProperties.isForce());
    filter.setOrder(Ordered.HIGHEST_PRECEDENCE);
    return filter;
}

@wilkinsona
Copy link
Member

@dsyer I'm not sure of your motivations for moving OrderedCharacterEncodingFilter's order nearer to zero. Any objections to moving it back to HIGHEST_PRECEDENCE rather than just slightly before the other filters that we auto-configure?

@dsyer
Copy link
Member

dsyer commented Sep 7, 2015

Don't think so.

@rreitmann
Copy link
Author

Thanks for the immediate feedback. We will go with the workaround for the time being and upgrade to 1.3.0.RC1 as soon as it is available.

odrotbohm added a commit to st-tu-dresden/salespoint that referenced this issue Oct 9, 2015
ghillert added a commit to devnexus/devnexus-site that referenced this issue Nov 10, 2015
@lewinras
Copy link

but , why I meet the same problem like it in 1.5.8.RELEASE???

@wilkinsona
Copy link
Member

@lewinras It’s impossible to say without more information. If you believe you’ve found a bug then please open a new issue with a minimal sample project that reproduces the problem.

@nargesfallahi
Copy link

@wilkinsona I was wondering if this bug still exists as I encountered it in my project. sending é in the GET request is decoded as é

@wilkinsona
Copy link
Member

As far as we know, this bug is fixed. You haven't said which version you're using, but if you're on 2.0 then please be aware of #11607.

@Dmitrii-Iakovenko
Copy link

Dmitrii-Iakovenko commented Sep 21, 2022

Good day. The problem is relevant again. Spring Boot 2.7.3 + Mustache. Solved by installing an encoder (not ordered).

But after adding Spring Security to the project, the order apparently changes, as described above.
In addition, the names of the Spring packages have changed.

This code works:

import org.springframework.boot.web.servlet.filter.OrderedCharacterEncodingFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static org.springframework.core.Ordered.HIGHEST_PRECEDENCE;

@Configuration
public class FiltersUTF8Config {

    @Bean
    // https://github.com/spring-projects/spring-boot/issues/3912
    public OrderedCharacterEncodingFilter setUTF8OrderedCharacterEncodingFilter() {
        var filter = new OrderedCharacterEncodingFilter();
        filter.setEncoding("UTF-8");
        filter.setForceEncoding(true);
        filter.setOrder(HIGHEST_PRECEDENCE);
        return filter;
    }

}

@wilkinsona
Copy link
Member

@Dmitrii-Iakovenko Can you please open a new issue with a minimal sample that reproduces your problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

6 participants