SEC-2221: Fix the ignored media types to use includes instead of equals

This commit is contained in:
Rob Winch 2013-08-15 13:58:50 -05:00
parent 54c2166567
commit 75fb971d23
2 changed files with 19 additions and 1 deletions

View File

@ -176,7 +176,7 @@ public final class MediaTypeRequestMatcher implements RequestMatcher {
return false;
}
for(MediaType httpRequestMediaType : httpRequestMediaTypes) {
if(ignoredMediaTypes.contains(httpRequestMediaType)) {
if(shouldIgnore(httpRequestMediaType)) {
continue;
}
if(useEquals) {
@ -191,6 +191,15 @@ public final class MediaTypeRequestMatcher implements RequestMatcher {
return false;
}
private boolean shouldIgnore(MediaType httpRequestMediaType) {
for(MediaType ignoredMediaType : ignoredMediaTypes) {
if(httpRequestMediaType.includes(ignoredMediaType)) {
return true;
}
}
return false;
}
/**
* If set to true, matches on exact {@link MediaType}, else uses
* {@link MediaType#isCompatibleWith(MediaType)}.

View File

@ -183,4 +183,13 @@ public class MediaTypeRequestMatcherTests {
assertThat(matcher.matches(request)).isTrue();
}
@Test
public void mediaAllQ08AndTextPlainIgnoreMediaTypeAll() throws HttpMediaTypeNotAcceptableException {
when(negotiationStrategy.resolveMediaTypes(any(NativeWebRequest.class))).thenReturn(Arrays.asList(MediaType.TEXT_PLAIN,MediaType.parseMediaType("*/*;q=0.8")));
matcher = new MediaTypeRequestMatcher(negotiationStrategy, MediaType.TEXT_HTML);
matcher.setIgnoredMediaTypes(Collections.singleton(MediaType.ALL));
assertThat(matcher.matches(request)).isFalse();
}
}