Skip to content

Commit

Permalink
Support Windows path in ContentDisposition::parse
Browse files Browse the repository at this point in the history
This commit makes sure that ContentDisposition::parse supports Windows
path with a backslash.

Closes gh-30111
  • Loading branch information
poutsma committed Mar 14, 2023
1 parent c3ce847 commit 1f8e9f5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1f8e9f5

Please sign in to comment.