Skip to content

Commit

Permalink
Use case-insensitive check for request conditions
Browse files Browse the repository at this point in the history
This commit ensures that the ConsumesRequestCondition and
ProducesRequestCondition use a case insensitive check when comparing
parameters.

Closes gh-29416
  • Loading branch information
poutsma committed Nov 2, 2022
1 parent 481389f commit 9e30615
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected boolean matchParameters(MediaType contentType) {
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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public void matchWithParameters() {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected boolean matchParameters(MediaType contentType) {
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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ public void matchWithParameters() {
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
Expand Down

0 comments on commit 9e30615

Please sign in to comment.