Browse Source

CommonsMultipartFile removes mixed separator paths from original filename

Issue: SPR-13662
pull/913/merge
Juergen Hoeller 9 years ago
parent
commit
5d9d88c44d
  1. 9
      spring-web/src/main/java/org/springframework/web/multipart/commons/CommonsMultipartFile.java
  2. 4
      spring-web/src/test/java/org/springframework/web/multipart/commons/CommonsMultipartResolverTests.java

9
spring-web/src/main/java/org/springframework/web/multipart/commons/CommonsMultipartFile.java

@ -78,12 +78,13 @@ public class CommonsMultipartFile implements MultipartFile, Serializable { @@ -78,12 +78,13 @@ public class CommonsMultipartFile implements MultipartFile, Serializable {
// Should never happen.
return "";
}
// Check for Unix-style path
int pos = filename.lastIndexOf("/");
if (pos == -1) {
int unixSep = filename.lastIndexOf("/");
// Check for Windows-style path
pos = filename.lastIndexOf("\\");
}
int winSep = filename.lastIndexOf("\\");
// Cut off at latest possible point
int pos = (winSep > unixSep ? winSep : unixSep);
if (pos != -1) {
// Any sort of path separator found...
return filename.substring(pos + 1);

4
spring-web/src/test/java/org/springframework/web/multipart/commons/CommonsMultipartResolverTests.java

@ -383,9 +383,9 @@ public class CommonsMultipartResolverTests { @@ -383,9 +383,9 @@ public class CommonsMultipartResolverTests {
MockFileItem fileItem1x = new MockFileItem(
"field1", "type1", empty ? "" : "field1.txt", empty ? "" : "text1");
MockFileItem fileItem2 = new MockFileItem(
"field2", "type2", empty ? "" : "C:/field2.txt", empty ? "" : "text2");
"field2", "type2", empty ? "" : "C:\\mypath/field2.txt", empty ? "" : "text2");
MockFileItem fileItem2x = new MockFileItem(
"field2x", "type2", empty ? "" : "C:\\field2x.txt", empty ? "" : "text2");
"field2x", "type2", empty ? "" : "C:/mypath\\field2x.txt", empty ? "" : "text2");
MockFileItem fileItem3 = new MockFileItem("field3", null, null, "value3");
MockFileItem fileItem4 = new MockFileItem("field4", "text/html; charset=iso-8859-1", null, "value4");
MockFileItem fileItem5 = new MockFileItem("field4", null, null, "value5");

Loading…
Cancel
Save