Browse Source

MimeTypeUtils trims parameter names / values

Issue: SPR-16630
pull/1746/merge
Rossen Stoyanchev 7 years ago
parent
commit
e00384a6fd
  1. 4
      spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java
  2. 12
      spring-core/src/test/java/org/springframework/util/MimeTypeTests.java

4
spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java

@ -225,8 +225,8 @@ public abstract class MimeTypeUtils { @@ -225,8 +225,8 @@ public abstract class MimeTypeUtils {
}
int eqIndex = parameter.indexOf('=');
if (eqIndex >= 0) {
String attribute = parameter.substring(0, eqIndex);
String value = parameter.substring(eqIndex + 1, parameter.length());
String attribute = parameter.substring(0, eqIndex).trim();
String value = parameter.substring(eqIndex + 1, parameter.length()).trim();
parameters.put(attribute, value);
}
}

12
spring-core/src/test/java/org/springframework/util/MimeTypeTests.java

@ -247,6 +247,18 @@ public class MimeTypeTests { @@ -247,6 +247,18 @@ public class MimeTypeTests {
assertEquals("'v>alue'", mimeType.getParameter("attr"));
}
@Test // SPR-16630
public void parseMimeTypeWithSpacesAroundEquals() {
MimeType mimeType = MimeTypeUtils.parseMimeType("multipart/x-mixed-replace;boundary = --myboundary");
assertEquals("--myboundary", mimeType.getParameter("boundary"));
}
@Test // SPR-16630
public void parseMimeTypeWithSpacesAroundEqualsAndQuotedValue() {
MimeType mimeType = MimeTypeUtils.parseMimeType("text/plain; foo = \" bar \" ");
assertEquals("\" bar \"", mimeType.getParameter("foo"));
}
@Test(expected = InvalidMimeTypeException.class)
public void parseMimeTypeIllegalQuotedParameterValue() {
MimeTypeUtils.parseMimeType("audio/*;attr=\"");

Loading…
Cancel
Save