Support escape character in ContentDisposition
Closes gh-23077
This commit is contained in:
parent
4523d01a50
commit
4f05da7fed
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2018 the original author or authors.
|
* Copyright 2002-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -331,6 +331,7 @@ public final class ContentDisposition {
|
||||||
do {
|
do {
|
||||||
int nextIndex = index + 1;
|
int nextIndex = index + 1;
|
||||||
boolean quoted = false;
|
boolean quoted = false;
|
||||||
|
boolean escaped = false;
|
||||||
while (nextIndex < headerValue.length()) {
|
while (nextIndex < headerValue.length()) {
|
||||||
char ch = headerValue.charAt(nextIndex);
|
char ch = headerValue.charAt(nextIndex);
|
||||||
if (ch == ';') {
|
if (ch == ';') {
|
||||||
|
@ -338,9 +339,10 @@ public final class ContentDisposition {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ch == '"') {
|
else if (!escaped && ch == '"') {
|
||||||
quoted = !quoted;
|
quoted = !quoted;
|
||||||
}
|
}
|
||||||
|
escaped = (!escaped && ch == '\\');
|
||||||
nextIndex++;
|
nextIndex++;
|
||||||
}
|
}
|
||||||
String part = headerValue.substring(index + 1, nextIndex).trim();
|
String part = headerValue.substring(index + 1, nextIndex).trim();
|
||||||
|
|
|
@ -79,6 +79,14 @@ public class ContentDispositionTests {
|
||||||
.filename("中文.txt", StandardCharsets.UTF_8).build(), disposition);
|
.filename("中文.txt", StandardCharsets.UTF_8).build(), disposition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // gh-23077
|
||||||
|
public void parseWithEscapedQuote() {
|
||||||
|
ContentDisposition disposition = ContentDisposition.parse(
|
||||||
|
"form-data; name=\"file\"; filename=\"\\\"The Twilight Zone\\\".txt\"; size=123");
|
||||||
|
assertEquals(ContentDisposition.builder("form-data").name("file")
|
||||||
|
.filename("\\\"The Twilight Zone\\\".txt").size(123L).build(), disposition);
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void parseEmpty() {
|
public void parseEmpty() {
|
||||||
ContentDisposition.parse("");
|
ContentDisposition.parse("");
|
||||||
|
|
Loading…
Reference in New Issue