larryi 02/02/01 20:46:01 Modified: util/java/org/apache/tomcat/util/buf UDecoder.java Log: In a query string, '+' is a substitute for space, but not in the path portion of a URL. Add methods that include a "query" parameter to control if the '+' should be converted to a space. Revision Changes Path 1.5 +46 -10 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.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- UDecoder.java 31 Dec 2001 18:20:04 -0000 1.4 +++ UDecoder.java 2 Feb 2002 04:46:01 -0000 1.5 @@ -78,9 +78,18 @@ { } + /** URLDecode, will modify the source. Includes converting + * '+' to ' '. + */ + public void convert( ByteChunk mb ) + throws IOException + { + convert(mb, true); + } + /** URLDecode, will modify the source. */ - public void convert(ByteChunk mb) + public void convert( ByteChunk mb, boolean query ) throws IOException { int start=mb.getOffset(); @@ -88,7 +97,9 @@ int end=mb.getEnd(); int idx= mb.indexOf( buff, start, end, '%' ); - int idx2= mb.indexOf( buff, start, end, '+' ); + int idx2=-1; + if( query ) + idx2= mb.indexOf( buff, start, end, '+' ); if( idx<0 && idx2<0 ) { return; } @@ -98,7 +109,7 @@ if( idx < 0 ) idx=idx2; for( int j=idx; j<end; j++, idx++ ) { - if( buff[ j ] == '+' ) { + if( buff[ j ] == '+' && query) { buff[idx]= (byte)' ' ; } else if( buff[ j ] != '%' ) { buff[idx]= buff[j]; @@ -127,17 +138,28 @@ // XXX What do we do about charset ???? /** In-buffer processing - the buffer will be modified + * Includes converting '+' to ' '. */ public void convert( CharChunk mb ) throws IOException { + convert(mb, true); + } + + /** In-buffer processing - the buffer will be modified + */ + public void convert( CharChunk mb, boolean query ) + throws IOException + { // log( "Converting a char chunk "); int start=mb.getOffset(); char buff[]=mb.getBuffer(); int cend=mb.getEnd(); int idx= mb.indexOf( buff, start, cend, '%' ); - int idx2= mb.indexOf( buff, start, cend, '+' ); + int idx2=-1; + if( query ) + idx2= mb.indexOf( buff, start, cend, '+' ); if( idx<0 && idx2<0 ) { return; } @@ -146,7 +168,7 @@ if( idx < 0 ) idx=idx2; for( int j=idx; j<cend; j++, idx++ ) { - if( buff[ j ] == '+' ) { + if( buff[ j ] == '+' && query ) { buff[idx]=( ' ' ); } else if( buff[ j ] != '%' ) { buff[idx]=buff[j]; @@ -170,24 +192,33 @@ } /** URLDecode, will modify the source + * Includes converting '+' to ' '. */ public void convert(MessageBytes mb) throws IOException { + convert(mb, true); + } + + /** URLDecode, will modify the source + */ + public void convert(MessageBytes mb, boolean query) + throws IOException + { switch (mb.getType()) { case MessageBytes.T_STR: String strValue=mb.toString(); if( strValue==null ) return; - mb.setString( convert( strValue )); + mb.setString( convert( strValue, query )); break; case MessageBytes.T_CHARS: CharChunk charC=mb.getCharChunk(); - convert( charC ); + convert( charC, query ); break; case MessageBytes.T_BYTES: ByteChunk bytesC=mb.getByteChunk(); - convert( bytesC ); + convert( bytesC, query ); break; } } @@ -196,9 +227,14 @@ // public final String convert(String str) { + return convert(str, true); + } + + public final String convert(String str, boolean query) + { if (str == null) return null; - if( str.indexOf( '+' ) <0 && str.indexOf( '%' ) < 0 ) + if( (!query || str.indexOf( '+' ) < 0) && str.indexOf( '%' ) < 0 ) return str; StringBuffer dec = new StringBuffer(); // decoded string output @@ -212,7 +248,7 @@ // look ahead to next URLencoded metacharacter, if any for (laPos = strPos; laPos < strLen; laPos++) { char laChar = str.charAt(laPos); - if ((laChar == '+') || (laChar == '%')) { + if ((laChar == '+' && query) || (laChar == '%')) { break; } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>