Skip to content

Commit 1f8e9f5

Browse files
committed
Support Windows path in ContentDisposition::parse
This commit makes sure that ContentDisposition::parse supports Windows path with a backslash. Closes gh-30111
1 parent c3ce847 commit 1f8e9f5

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

spring-web/src/main/java/org/springframework/http/ContentDisposition.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,11 @@ private static String decodeQuotedPairs(String filename) {
624624
char c = filename.charAt(i);
625625
if (filename.charAt(i) == '\\' && i + 1 < length) {
626626
i++;
627-
sb.append(filename.charAt(i));
627+
char next = filename.charAt(i);
628+
if (next != '"' && next != '\\') {
629+
sb.append(c);
630+
}
631+
sb.append(next);
628632
}
629633
else {
630634
sb.append(c);

spring-web/src/test/java/org/springframework/http/ContentDispositionTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@ void parseBackslashInLastPosition() {
169169
assertThat(cd.toString()).isEqualTo("form-data; name=\"foo\"; filename=\"bar\\\\\"");
170170
}
171171

172+
@Test
173+
void parseWindowsPath() {
174+
ContentDisposition cd = ContentDisposition.parse("form-data; name=\"foo\"; filename=\"D:\\foo\\bar.txt\"");
175+
assertThat(cd.getName()).isEqualTo("foo");
176+
assertThat(cd.getFilename()).isEqualTo("D:\\foo\\bar.txt");
177+
assertThat(cd.toString()).isEqualTo("form-data; name=\"foo\"; filename=\"D:\\\\foo\\\\bar.txt\"");
178+
}
179+
172180

173181
@SuppressWarnings("deprecation")
174182
@Test

0 commit comments

Comments
 (0)