Hi All, Sorry to pipe up so late on this, but a recent re-org still has me still swamped at work.
I'm not sure if the patch below is doing exactly what was intended. I am unable to get the servlet example provided by Mirek Hankus in: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=24557 to work in Tomcat 5.0.14, even with URIEncoding="UTF-8" specified on the connector. It seems to me that it should work with a request which has a query parameter that is UTF-8 encoded and URL encoded, as this example implements. Note that the UTF-8 encoding is applied first, followed by the URL encoding, which makes sense. The reason it doesn't work in Tomcat 5 is that, in spite of URIEncoding="UTF-8", the added code: + decodedQuery.setEncoding(queryStringEncoding); + decodedQuery.toChars(); is applying the UTF-8 decoding prior to URL decoding, which I think is guaranteed to have no effect. Prior to this change, the URL decoding would occur first, followed the by UTF-8 decoding, which successfully unwinds the encoding of the query parameter. The current implementation doesn't seem right, or am I missing something? Note that this is separate from the "should setCharacterEncoding() apply to query parameters issue", which I think gave rise to this change. I don't have a disagreement with that decision. Assuming this is a bug, I think it would be good to address this prior to declaring Tomcat 5.0.x as stable. Unfortunately, I haven't had time yet look for a good solution. I'll continue looking, but if somebody comes up with one before me, feel free to commit it. I'm still familiarizing my self with how things are plugged together in this case. I'm willing to back port any needed changes to Tomcat 4.1.x. SAS has a number internationalized webapps that rely on being able to UTF-8/URL encode parameters into HREFs. Currently they are all broken on Tomcat 4.1.29, and can't be made to work unless the URIEncoding property is added to the connector. I'm not sure how many others would be in the same boat. Cheers, Larry > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Sent: Sunday, September 07, 2003 3:37 AM > To: [EMAIL PROTECTED] > Subject: cvs commit: > jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/htt > p Parameters.java > > > remm 2003/09/07 00:37:12 > > Modified: util/java/org/apache/tomcat/util/http Parameters.java > Log: > - Handle query string decoding as a special case. > - Char decoding is not lazy anymore (if parameter parsing > is requested), but > the difference was mostly rhetorical. > - This will change behavior in TC 3.3 (to be identical with > the new TC 5 > default). > - I didn't test the change with UTF8. > > Revision Changes Path > 1.11 +25 -8 > jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/htt > p/Parameters.java > > Index: Parameters.java > =================================================================== > RCS file: > /home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomca > t/util/http/Parameters.java,v > retrieving revision 1.10 > retrieving revision 1.11 > diff -u -r1.10 -r1.11 > --- Parameters.java 2 Sep 2003 21:34:39 -0000 1.10 > +++ Parameters.java 7 Sep 2003 07:37:12 -0000 1.11 > @@ -101,6 +101,7 @@ > private Parameters currentChild=null; > > String encoding=null; > + String queryStringEncoding=null; > > /** > * > @@ -122,6 +123,11 @@ > if(debug>0) log( "Set encoding to " + s ); > } > > + public void setQueryStringEncoding( String s ) { > + queryStringEncoding=s; > + if(debug>0) log( "Set query string encoding to " + s ); > + } > + > public void recycle() { > super.recycle(); > paramHashStringArray.clear(); > @@ -281,22 +287,33 @@ > public void handleQueryParameters() { > if( didQueryParameters ) return; > > - if( queryMB != null) > - queryMB.setEncoding( encoding ); > didQueryParameters=true; > - if( debug > 0 ) > - log( "Decoding query " + queryMB + " " + encoding); > - > + > if( queryMB==null || queryMB.isNull() ) > return; > > try { > - decodedQuery.duplicate( queryMB ); > - decodedQuery.setEncoding(encoding); > + decodedQuery.duplicate( queryMB ); > + if (queryStringEncoding == null) { > + ByteChunk bc = decodedQuery.getByteChunk(); > + CharChunk cc = decodedQuery.getCharChunk(); > + cc.allocate(bc.getLength(), -1); > + // Default encoding: fast conversion > + byte[] bbuf = bc.getBuffer(); > + char[] cbuf = cc.getBuffer(); > + int start = bc.getStart(); > + for (int i = 0; i < bc.getLength(); i++) { > + cbuf[i] = (char) (bbuf[i + start] & 0xff); > + } > + decodedQuery.setChars(cbuf, 0, bc.getLength()); > + } else { > + decodedQuery.setEncoding(queryStringEncoding); > + decodedQuery.toChars(); > + } > } catch( IOException ex ) { > } > if( debug > 0 ) > - log( "Decoding query " + decodedQuery + " " + encoding); > + log( "Decoding query " + decodedQuery + " " + > queryStringEncoding); > > processParameters( decodedQuery ); > } > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]