costin 01/06/19 22:24:47
Modified: util/java/org/apache/tomcat/util/buf ByteChunk.java
UDecoder.java
util/java/org/apache/tomcat/util/http Parameters.java
Log:
Few fixes related with decoding 8859_1.
Replaced default encoding from UTF8 to 8859_1. While I think it would be
better to default to UTF8 in low-level utils like MessageBytes, fact is that
most of the uses for MB is in servlet container where 8859_1 is required
as default impl. That's pretty bad as most RFCs and recent standards seem to be
moving to UTF.
( we could make it non-final, but than it would be even worse ).
The solution is to make sure the encoding is propagated and set by the caller
( we could throw an exception - just to make sure the problem is handled )
Also removed an extra log.
Revision Changes Path
1.4 +8 -2
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/ByteChunk.java
Index: ByteChunk.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/ByteChunk.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ByteChunk.java 2001/06/03 20:34:25 1.3
+++ ByteChunk.java 2001/06/20 05:24:47 1.4
@@ -100,7 +100,13 @@
}
// --------------------
-
+
+ /** Default encoding used to convert to strings. It should be UTF8,
+ as most standards seem to converge, but the servlet API requires
+ 8859_1, and this object is used mostly for servlets.
+ */
+ public static final String DEFAULT_CHARACTER_ENCODING="ISO-8859-1";
+
// byte[]
private byte[] buff;
@@ -409,7 +415,7 @@
}
String strValue=null;
try {
- if( enc==null ) enc="UTF8";
+ if( enc==null ) enc=DEFAULT_CHARACTER_ENCODING;
return new String( buff, start, end-start, enc );
/*
Does not improve the speed too much on most systems,
1.3 +2 -2
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/UDecoder.java
Index: UDecoder.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/UDecoder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- UDecoder.java 2001/06/12 14:52:01 1.2
+++ UDecoder.java 2001/06/20 05:24:47 1.3
@@ -119,7 +119,7 @@
}
mb.setEnd( idx );
-
+
return;
}
@@ -131,7 +131,7 @@
public void convert( CharChunk mb )
throws IOException
{
- log( "Converting a char chunk ");
+ // log( "Converting a char chunk ");
int start=mb.getOffset();
char buff[]=mb.getBuffer();
int cend=mb.getEnd();
1.4 +5 -1
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http/Parameters.java
Index: Parameters.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http/Parameters.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Parameters.java 2001/06/11 20:07:02 1.3
+++ Parameters.java 2001/06/20 05:24:47 1.4
@@ -115,6 +115,7 @@
public void setEncoding( String s ) {
encoding=s;
+ if(debug>0) log( "Set encoding to " + s );
}
public void recycle() {
@@ -168,6 +169,7 @@
// the head will be the new element.
currentChild=currentChild.child;
+ currentChild.setEncoding( encoding );
}
/** Discard the last child. This happens when we return from a
@@ -255,7 +257,8 @@
*/
public void handleQueryParameters() {
if( didQueryParameters ) return;
-
+
+ queryMB.setEncoding( encoding );
didQueryParameters=true;
if( debug > 0 )
log( "Decoding query " + queryMB + " " + encoding);
@@ -265,6 +268,7 @@
try {
decodedQuery.duplicate( queryMB );
+ decodedQuery.setEncoding(encoding);
} catch( IOException ex ) {
}
if( debug > 0 )