You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2003/09/07 09:37:12 UTC

cvs commit: jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http 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/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.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 );
       }