Skip to content
This repository was archived by the owner on Jul 7, 2023. It is now read-only.

Commit a01feaf

Browse files
committed
WINK-371 - Force UTF-8 when reading Multi-Part MIME.
git-svn-id: https://svn.apache.org/repos/asf/wink/trunk@1666780 13f79535-47bb-0310-9956-ffa450edef68
1 parent 598af98 commit a01feaf

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

wink-common/src/main/java/org/apache/wink/common/internal/providers/multipart/MultiPartParser.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@
2222

2323
import java.io.IOException;
2424
import java.io.InputStream;
25+
import java.io.UnsupportedEncodingException;
2526

2627
import javax.ws.rs.core.MultivaluedMap;
2728

2829
import org.apache.wink.common.internal.CaseInsensitiveMultivaluedMap;
2930
import org.apache.wink.common.internal.i18n.Messages;
31+
import org.slf4j.Logger;
32+
import org.slf4j.LoggerFactory;
3033

3134
/*
3235
* TODO: Add the option to get the preamble
@@ -37,6 +40,9 @@
3740
public class MultiPartParser {
3841
public final static String SEP = "\n"; //$NON-NLS-1$
3942

43+
private static final Logger logger = LoggerFactory.getLogger(MultiPartParser.class);
44+
private final static String UTF8 = "UTF-8"; //$NON-NLS-1$
45+
4046
private InputStream is;
4147
private byte[] boundaryBA;
4248
static private byte[] boundaryDelimiterBA = "--".getBytes(); //$NON-NLS-1$
@@ -64,7 +70,11 @@ public class MultiPartParser {
6470

6571
public MultiPartParser(InputStream is, String boundary) {
6672
this.is = is;
67-
boundaryBA = ("--" + boundary).getBytes(); //$NON-NLS-1$
73+
try {
74+
boundaryBA = ("--" + boundary).getBytes(UTF8); //$NON-NLS-1$
75+
} catch(UnsupportedEncodingException e) {
76+
logger.debug("Error parsing multi part: " + e.getMessage(), e);
77+
}
6878
// make sure to allocate a buffer that is at least double then the
6979
// boundary length
7080
int buffLength = Math.max(8192, boundaryBA.length * 2);
@@ -297,7 +307,7 @@ private String readLine() throws IOException {
297307
return null;
298308
}
299309

300-
String hdr = new String(buff, buffIdx, lineIdx);
310+
String hdr = new String(buff, buffIdx, lineIdx, UTF8);
301311
buffIdx += lineIdx + breakeSize;
302312
return hdr;
303313
}

0 commit comments

Comments
 (0)