Same fix for Netty V4 for issue #1313

Remove encodeAttribute/decodeAttribute for Multipart element
Replace where necessary by cleanString (to remove '"') on name part (not
on value part)
This commit is contained in:
Frederic Bregier 2013-05-08 12:34:02 +02:00 committed by Norman Maurer
parent c07234ed72
commit 6c0b2be412
2 changed files with 11 additions and 18 deletions

View File

@ -788,7 +788,7 @@ public class HttpPostRequestDecoder implements Iterator<InterfaceHttpData> {
if (currentAttribute == null) {
try {
currentAttribute = factory.createAttribute(request,
decodeAttribute(nameAttribute.getValue(), charset));
cleanString(nameAttribute.getValue()));
} catch (NullPointerException e) {
throw new ErrorDataDecoderException(e);
} catch (IllegalArgumentException e) {
@ -963,8 +963,7 @@ public class HttpPostRequestDecoder implements Iterator<InterfaceHttpData> {
Attribute attribute;
try {
attribute = factory.createAttribute(request,
decodeAttribute(values[0].trim(), charset),
decodeAttribute(cleanString(values[1]), charset));
cleanString(values[0]), values[1]);
} catch (NullPointerException e) {
throw new ErrorDataDecoderException(e);
} catch (IllegalArgumentException e) {
@ -1024,8 +1023,7 @@ public class HttpPostRequestDecoder implements Iterator<InterfaceHttpData> {
Attribute attribute;
try {
attribute = factory.createAttribute(request,
decodeAttribute(contents[0].trim(), charset),
decodeAttribute(cleanString(contents[i]), charset));
cleanString(contents[0]), contents[i]);
} catch (NullPointerException e) {
throw new ErrorDataDecoderException(e);
} catch (IllegalArgumentException e) {
@ -1126,8 +1124,7 @@ public class HttpPostRequestDecoder implements Iterator<InterfaceHttpData> {
}
try {
currentFileUpload = factory.createFileUpload(request,
decodeAttribute(nameAttribute.getValue(), charset),
decodeAttribute(filenameAttribute.getValue(), charset),
cleanString(nameAttribute.getValue()), cleanString(filenameAttribute.getValue()),
contentTypeAttribute.getValue(), mechanism.value(), localCharset,
size);
} catch (NullPointerException e) {

View File

@ -487,10 +487,10 @@ public class HttpPostRequestEncoder implements ChunkedMessageInput<HttpContent>
// content-disposition: form-data; name="field1"
Attribute attribute = (Attribute) data;
internal.addValue(HttpPostBodyUtil.CONTENT_DISPOSITION + ": " + HttpPostBodyUtil.FORM_DATA + "; "
+ HttpPostBodyUtil.NAME + "=\"" + encodeAttribute(attribute.getName(), charset) + "\"\r\n");
+ HttpPostBodyUtil.NAME + "=\"" + attribute.getName() + "\"\r\n");
Charset localcharset = attribute.getCharset();
if (localcharset != null) {
// Content-Type: charset=charset
// Content-Type: text/plain; charset=charset
internal.addValue(HttpHeaders.Names.CONTENT_TYPE + ": " +
HttpPostBodyUtil.DEFAULT_TEXT_CONTENT_TYPE + "; " +
HttpHeaders.Values.CHARSET + '='
@ -560,14 +560,12 @@ public class HttpPostRequestEncoder implements ChunkedMessageInput<HttpContent>
// remove past size
globalBodySize -= pastAttribute.size();
String replacement = HttpPostBodyUtil.CONTENT_DISPOSITION + ": " + HttpPostBodyUtil.FORM_DATA
+ "; " + HttpPostBodyUtil.NAME + "=\"" + encodeAttribute(fileUpload.getName(), charset)
+ "\"\r\n";
+ "; " + HttpPostBodyUtil.NAME + "=\"" + fileUpload.getName() + "\"\r\n";
replacement += HttpHeaders.Names.CONTENT_TYPE + ": " + HttpPostBodyUtil.MULTIPART_MIXED + "; "
+ HttpHeaders.Values.BOUNDARY + '=' + multipartMixedBoundary + "\r\n\r\n";
replacement += "--" + multipartMixedBoundary + "\r\n";
replacement += HttpPostBodyUtil.CONTENT_DISPOSITION + ": " + HttpPostBodyUtil.FILE + "; "
+ HttpPostBodyUtil.FILENAME + "=\"" + encodeAttribute(fileUpload.getFilename(), charset)
+ "\"\r\n";
+ HttpPostBodyUtil.FILENAME + "=\"" + fileUpload.getFilename() + "\"\r\n";
pastAttribute.setValue(replacement, 1);
// update past size
globalBodySize += pastAttribute.size();
@ -594,16 +592,14 @@ public class HttpPostRequestEncoder implements ChunkedMessageInput<HttpContent>
internal.addValue("--" + multipartMixedBoundary + "\r\n");
// Content-Disposition: file; filename="file1.txt"
internal.addValue(HttpPostBodyUtil.CONTENT_DISPOSITION + ": " + HttpPostBodyUtil.FILE + "; "
+ HttpPostBodyUtil.FILENAME + "=\"" + encodeAttribute(fileUpload.getFilename(), charset)
+ "\"\r\n");
+ HttpPostBodyUtil.FILENAME + "=\"" + fileUpload.getFilename() + "\"\r\n");
} else {
internal.addValue("--" + multipartDataBoundary + "\r\n");
// Content-Disposition: form-data; name="files";
// filename="file1.txt"
internal.addValue(HttpPostBodyUtil.CONTENT_DISPOSITION + ": " + HttpPostBodyUtil.FORM_DATA + "; "
+ HttpPostBodyUtil.NAME + "=\"" + encodeAttribute(fileUpload.getName(), charset) + "\"; "
+ HttpPostBodyUtil.FILENAME + "=\"" + encodeAttribute(fileUpload.getFilename(), charset)
+ "\"\r\n");
+ HttpPostBodyUtil.NAME + "=\"" + fileUpload.getName() + "\"; "
+ HttpPostBodyUtil.FILENAME + "=\"" + fileUpload.getFilename() + "\"\r\n");
}
// Content-Type: image/gif
// Content-Type: text/plain; charset=ISO-8859-1