diff --git a/spring-web/src/main/java/org/springframework/http/ContentDisposition.java b/spring-web/src/main/java/org/springframework/http/ContentDisposition.java index c725123e294d..8516e898e952 100644 --- a/spring-web/src/main/java/org/springframework/http/ContentDisposition.java +++ b/spring-web/src/main/java/org/springframework/http/ContentDisposition.java @@ -624,7 +624,11 @@ private static String decodeQuotedPairs(String filename) { char c = filename.charAt(i); if (filename.charAt(i) == '\\' && i + 1 < length) { i++; - sb.append(filename.charAt(i)); + char next = filename.charAt(i); + if (next != '"' && next != '\\') { + sb.append(c); + } + sb.append(next); } else { sb.append(c); diff --git a/spring-web/src/test/java/org/springframework/http/ContentDispositionTests.java b/spring-web/src/test/java/org/springframework/http/ContentDispositionTests.java index ca2a7cb0aa50..ac4a83154304 100644 --- a/spring-web/src/test/java/org/springframework/http/ContentDispositionTests.java +++ b/spring-web/src/test/java/org/springframework/http/ContentDispositionTests.java @@ -169,6 +169,14 @@ void parseBackslashInLastPosition() { assertThat(cd.toString()).isEqualTo("form-data; name=\"foo\"; filename=\"bar\\\\\""); } + @Test + void parseWindowsPath() { + ContentDisposition cd = ContentDisposition.parse("form-data; name=\"foo\"; filename=\"D:\\foo\\bar.txt\""); + assertThat(cd.getName()).isEqualTo("foo"); + assertThat(cd.getFilename()).isEqualTo("D:\\foo\\bar.txt"); + assertThat(cd.toString()).isEqualTo("form-data; name=\"foo\"; filename=\"D:\\\\foo\\\\bar.txt\""); + } + @SuppressWarnings("deprecation") @Test