Skip to content

Commit

Permalink
Order char encoding filter so it sets encoding before request is read
Browse files Browse the repository at this point in the history
For the character encoding filter to work, it's vital that it sets
the request's encoding before any other filters attempt to read the
request. This commit updates the order of
OrderedCharacterEncodingFilter to be HIGHEST_PRECEDENCE and improves
the existing test to check that the ordering is as required.

Closes gh-3912
  • Loading branch information
wilkinsona committed Sep 21, 2015
1 parent 702b8d0 commit c3e447c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.junit.rules.ExpectedException;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.context.web.OrderedHiddenHttpMethodFilter;
import org.springframework.boot.context.web.OrderedHttpPutFormContentFilter;
import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -145,8 +147,13 @@ public CharacterEncodingFilter myCharacterEncodingFilter() {
static class OrderedConfiguration {

@Bean
public HiddenHttpMethodFilter hiddenHttpMethodFilter() {
return new HiddenHttpMethodFilter();
public OrderedHiddenHttpMethodFilter hiddenHttpMethodFilter() {
return new OrderedHiddenHttpMethodFilter();
}

@Bean
public OrderedHttpPutFormContentFilter httpPutFormContentFilter() {
return new OrderedHttpPutFormContentFilter();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.springframework.boot.context.web;

import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.core.Ordered;
import org.springframework.web.filter.CharacterEncodingFilter;

Expand All @@ -29,7 +28,7 @@
public class OrderedCharacterEncodingFilter extends CharacterEncodingFilter implements
Ordered {

private int order = FilterRegistrationBean.REQUEST_WRAPPER_FILTER_MAX_ORDER - 9800;
private int order = Ordered.HIGHEST_PRECEDENCE;

@Override
public int getOrder() {
Expand Down

0 comments on commit c3e447c

Please sign in to comment.