[#1313] Fix for Multipart name and value that should not be encoded, except charset if specified

This commit is contained in:
Frederic Bregier 2013-05-07 13:43:25 +02:00 committed by Norman Maurer
parent 60695012ab
commit 1615009f5a
2 changed files with 10 additions and 15 deletions

View File

@ -784,7 +784,7 @@ public class HttpPostRequestDecoder {
if (currentAttribute == null) {
try {
currentAttribute = factory.createAttribute(request,
decodeAttribute(cleanString(nameAttribute.getValue()), charset));
cleanString(nameAttribute.getValue()));
} catch (NullPointerException e) {
throw new ErrorDataDecoderException(e);
} catch (IllegalArgumentException e) {
@ -960,8 +960,7 @@ public class HttpPostRequestDecoder {
Attribute attribute;
try {
attribute = factory.createAttribute(request,
decodeAttribute(cleanString(values[0].trim()), charset),
decodeAttribute(cleanString(values[1]), charset));
cleanString(values[0]), values[1]);
} catch (NullPointerException e) {
throw new ErrorDataDecoderException(e);
} catch (IllegalArgumentException e) {
@ -1032,8 +1031,7 @@ public class HttpPostRequestDecoder {
Attribute attribute;
try {
attribute = factory.createAttribute(request,
decodeAttribute(cleanString(contents[0].trim()), charset),
decodeAttribute(cleanString(contents[i]), charset));
cleanString(contents[0]), contents[i]);
} catch (NullPointerException e) {
throw new ErrorDataDecoderException(e);
} catch (IllegalArgumentException e) {
@ -1147,8 +1145,7 @@ public class HttpPostRequestDecoder {
try {
currentFileUpload = factory.createFileUpload(
request,
decodeAttribute(cleanString(nameAttribute.getValue()), charset),
decodeAttribute(cleanString(filenameAttribute.getValue()), charset),
cleanString(nameAttribute.getValue()), cleanString(filenameAttribute.getValue()),
contentTypeAttribute.getValue(), mechanism.value(),
localCharset, size);
} catch (NullPointerException e) {

View File

@ -457,8 +457,7 @@ public class HttpPostRequestEncoder implements ChunkedInput {
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
@ -529,15 +528,14 @@ public class HttpPostRequestEncoder implements ChunkedInput {
globalBodySize -= pastAttribute.size();
String replacement = HttpPostBodyUtil.CONTENT_DISPOSITION + ": " +
HttpPostBodyUtil.FORM_DATA + "; " + HttpPostBodyUtil.NAME + "=\"" +
encodeAttribute(fileUpload.getName(), charset) + "\"\r\n";
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";
fileUpload.getFilename() + "\"\r\n";
pastAttribute.setValue(replacement, 1);
// update past size
globalBodySize += pastAttribute.size();
@ -563,16 +561,16 @@ public class HttpPostRequestEncoder implements ChunkedInput {
// Content-Disposition: file; filename="file1.txt"
internal.addValue(HttpPostBodyUtil.CONTENT_DISPOSITION + ": " +
HttpPostBodyUtil.FILE + "; " + HttpPostBodyUtil.FILENAME + "=\"" +
encodeAttribute(fileUpload.getFilename(), charset) +
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) + "\"; " +
fileUpload.getName() + "\"; " +
HttpPostBodyUtil.FILENAME + "=\"" +
encodeAttribute(fileUpload.getFilename(), charset) +
fileUpload.getFilename() +
"\"\r\n");
}
// Content-Type: image/gif