Skip to content

Commit

Permalink
Use Charset rather than encoding name to create B2CConvertor
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1701116 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Sep 3, 2015
1 parent cb1899f commit 6ec09aa
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion java/org/apache/catalina/connector/CoyoteAdapter.java
Expand Up @@ -1077,7 +1077,7 @@ protected void convertURI(MessageBytes uri, Request request) throws IOException
B2CConverter conv = request.getURIConverter(); B2CConverter conv = request.getURIConverter();
try { try {
if (conv == null) { if (conv == null) {
conv = new B2CConverter(enc, true); conv = new B2CConverter(B2CConverter.getCharset(enc), true);
request.setURIConverter(conv); request.setURIConverter(conv);
} else { } else {
conv.recycle(); conv.recycle();
Expand Down
4 changes: 2 additions & 2 deletions java/org/apache/catalina/connector/InputBuffer.java
Expand Up @@ -565,7 +565,7 @@ protected void setConverter() throws IOException {


@Override @Override
public B2CConverter run() throws IOException { public B2CConverter run() throws IOException {
return new B2CConverter(enc); return new B2CConverter(charset);
} }
} }
); );
Expand All @@ -576,7 +576,7 @@ public B2CConverter run() throws IOException {
} }
} }
} else { } else {
conv = new B2CConverter(enc); conv = new B2CConverter(charset);
} }
encoders.put(charset, conv); encoders.put(charset, conv);
} }
Expand Down
8 changes: 3 additions & 5 deletions java/org/apache/tomcat/util/buf/B2CConverter.java
Expand Up @@ -97,12 +97,11 @@ public static Charset getCharsetLower(String lowerCaseEnc)
*/ */
private final ByteBuffer leftovers; private final ByteBuffer leftovers;


public B2CConverter(String encoding) throws IOException { public B2CConverter(Charset charset) {
this(encoding, false); this(charset, false);
} }


public B2CConverter(String encoding, boolean replaceOnError) public B2CConverter(Charset charset, boolean replaceOnError) {
throws IOException {
byte[] left = new byte[LEFTOVER_SIZE]; byte[] left = new byte[LEFTOVER_SIZE];
leftovers = ByteBuffer.wrap(left); leftovers = ByteBuffer.wrap(left);
CodingErrorAction action; CodingErrorAction action;
Expand All @@ -111,7 +110,6 @@ public B2CConverter(String encoding, boolean replaceOnError)
} else { } else {
action = CodingErrorAction.REPORT; action = CodingErrorAction.REPORT;
} }
Charset charset = getCharset(encoding);
// Special case. Use the Apache Harmony based UTF-8 decoder because it // Special case. Use the Apache Harmony based UTF-8 decoder because it
// - a) rejects invalid sequences that the JVM decoder does not // - a) rejects invalid sequences that the JVM decoder does not
// - b) fails faster for some invalid sequences // - b) fails faster for some invalid sequences
Expand Down
9 changes: 5 additions & 4 deletions test/org/apache/tomcat/util/buf/TestB2CConverter.java
Expand Up @@ -18,6 +18,7 @@


import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.MalformedInputException; import java.nio.charset.MalformedInputException;
import java.nio.charset.StandardCharsets;
import java.util.Locale; import java.util.Locale;


import org.junit.Assert; import org.junit.Assert;
Expand Down Expand Up @@ -48,7 +49,7 @@ public void testManyMessage() throws Exception {
} }


private void testMessages(int msgCount) throws Exception { private void testMessages(int msgCount) throws Exception {
B2CConverter conv = new B2CConverter("UTF-16"); B2CConverter conv = new B2CConverter(StandardCharsets.UTF_16);


ByteChunk bc = new ByteChunk(); ByteChunk bc = new ByteChunk();
CharChunk cc = new CharChunk(32); CharChunk cc = new CharChunk(32);
Expand Down Expand Up @@ -96,7 +97,7 @@ public void testLeftoverSize() {
@Test(expected=MalformedInputException.class) @Test(expected=MalformedInputException.class)
public void testBug54602a() throws Exception { public void testBug54602a() throws Exception {
// Check invalid input is rejected straight away // Check invalid input is rejected straight away
B2CConverter conv = new B2CConverter("UTF-8"); B2CConverter conv = new B2CConverter(StandardCharsets.UTF_8);
ByteChunk bc = new ByteChunk(); ByteChunk bc = new ByteChunk();
CharChunk cc = new CharChunk(); CharChunk cc = new CharChunk();


Expand All @@ -109,7 +110,7 @@ public void testBug54602a() throws Exception {
@Test(expected=MalformedInputException.class) @Test(expected=MalformedInputException.class)
public void testBug54602b() throws Exception { public void testBug54602b() throws Exception {
// Check partial input is rejected // Check partial input is rejected
B2CConverter conv = new B2CConverter("UTF-8"); B2CConverter conv = new B2CConverter(StandardCharsets.UTF_8);
ByteChunk bc = new ByteChunk(); ByteChunk bc = new ByteChunk();
CharChunk cc = new CharChunk(); CharChunk cc = new CharChunk();


Expand All @@ -122,7 +123,7 @@ public void testBug54602b() throws Exception {
@Test @Test
public void testBug54602c() throws Exception { public void testBug54602c() throws Exception {
// Check partial input is rejected once it is known to be all available // Check partial input is rejected once it is known to be all available
B2CConverter conv = new B2CConverter("UTF-8"); B2CConverter conv = new B2CConverter(StandardCharsets.UTF_8);
ByteChunk bc = new ByteChunk(); ByteChunk bc = new ByteChunk();
CharChunk cc = new CharChunk(); CharChunk cc = new CharChunk();


Expand Down

0 comments on commit 6ec09aa

Please sign in to comment.