From 1615009f5aab59571382958958211ed0729b2ddc Mon Sep 17 00:00:00 2001 From: Frederic Bregier Date: Tue, 7 May 2013 13:43:25 +0200 Subject: [PATCH] [#1313] Fix for Multipart name and value that should not be encoded, except charset if specified --- .../http/multipart/HttpPostRequestDecoder.java | 11 ++++------- .../http/multipart/HttpPostRequestEncoder.java | 14 ++++++-------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/jboss/netty/handler/codec/http/multipart/HttpPostRequestDecoder.java b/src/main/java/org/jboss/netty/handler/codec/http/multipart/HttpPostRequestDecoder.java index 619810ab52..4311882318 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/multipart/HttpPostRequestDecoder.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/multipart/HttpPostRequestDecoder.java @@ -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) { diff --git a/src/main/java/org/jboss/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java b/src/main/java/org/jboss/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java index 4fbb8faff4..29fecaaac6 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/multipart/HttpPostRequestEncoder.java @@ -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