Use case-insensitive check for request conditions

This commit ensures that the ConsumesRequestCondition and
ProducesRequestCondition use a case insensitive check when comparing
parameters.

Closes gh-29416
This commit is contained in:
Arjen Poutsma
2022-11-02 14:29:08 +01:00
parent 481389f761
commit 9e306151c7
4 changed files with 10 additions and 2 deletions

View File

@@ -85,7 +85,7 @@ abstract class AbstractMediaTypeExpression implements Comparable<AbstractMediaTy
for (Map.Entry<String, String> entry : getMediaType().getParameters().entrySet()) {
if (StringUtils.hasText(entry.getValue())) {
String value = contentType.getParameter(entry.getKey());
if (StringUtils.hasText(value) && !entry.getValue().equals(value)) {
if (StringUtils.hasText(value) && !entry.getValue().equalsIgnoreCase(value)) {
return false;
}
}

View File

@@ -98,6 +98,10 @@ public class ConsumesRequestConditionTests {
condition = new ConsumesRequestCondition(base);
exchange = postExchange(base + ";profile=\"a\"");
assertThat(condition.getMatchingCondition(exchange)).isNotNull();
condition = new ConsumesRequestCondition(base + ";profile=\"a\"");
exchange = postExchange(base + ";profile=\"A\"");
assertThat(condition.getMatchingCondition(exchange)).isNotNull();
}
@Test

View File

@@ -85,7 +85,7 @@ abstract class AbstractMediaTypeExpression implements MediaTypeExpression, Compa
for (Map.Entry<String, String> entry : getMediaType().getParameters().entrySet()) {
if (StringUtils.hasText(entry.getValue())) {
String value = contentType.getParameter(entry.getKey());
if (StringUtils.hasText(value) && !entry.getValue().equals(value)) {
if (StringUtils.hasText(value) && !entry.getValue().equalsIgnoreCase(value)) {
return false;
}
}

View File

@@ -107,6 +107,10 @@ public class ConsumesRequestConditionTests {
condition = new ConsumesRequestCondition(base);
request.setContentType(base + ";profile=\"a\"");
assertThat(condition.getMatchingCondition(request)).isNotNull();
condition = new ConsumesRequestCondition(base + ";profile=\"a\"");
request.setContentType(base + ";profile=\"A\"");
assertThat(condition.getMatchingCondition(request)).isNotNull();
}
@Test