Support Windows path in ContentDisposition::parse
This commit makes sure that ContentDisposition::parse supports Windows path with a backslash. Closes gh-30111
This commit is contained in:
parent
c3ce847871
commit
1f8e9f5c55
|
|
@ -624,7 +624,11 @@ public final class ContentDisposition {
|
||||||
char c = filename.charAt(i);
|
char c = filename.charAt(i);
|
||||||
if (filename.charAt(i) == '\\' && i + 1 < length) {
|
if (filename.charAt(i) == '\\' && i + 1 < length) {
|
||||||
i++;
|
i++;
|
||||||
sb.append(filename.charAt(i));
|
char next = filename.charAt(i);
|
||||||
|
if (next != '"' && next != '\\') {
|
||||||
|
sb.append(c);
|
||||||
|
}
|
||||||
|
sb.append(next);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sb.append(c);
|
sb.append(c);
|
||||||
|
|
|
||||||
|
|
@ -169,6 +169,14 @@ class ContentDispositionTests {
|
||||||
assertThat(cd.toString()).isEqualTo("form-data; name=\"foo\"; filename=\"bar\\\\\"");
|
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")
|
@SuppressWarnings("deprecation")
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue