adammurdoch 2003/06/24 03:38:16 Modified: vfs/src/java/org/apache/commons/vfs/provider GenericFileName.java UriParser.java vfs/src/test/org/apache/commons/vfs/provider/test GenericFileNameTestCase.java Log: Encode and decode username and password as part of GenericFileName. Patch submitted by Jeff Barrett. Revision Changes Path 1.9 +8 -8 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/GenericFileName.java Index: GenericFileName.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/GenericFileName.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- GenericFileName.java 17 Mar 2003 09:07:32 -0000 1.8 +++ GenericFileName.java 24 Jun 2003 10:38:16 -0000 1.9 @@ -55,8 +55,8 @@ */ package org.apache.commons.vfs.provider; -import org.apache.commons.vfs.FileSystemException; import org.apache.commons.vfs.FileName; +import org.apache.commons.vfs.FileSystemException; /** * A file name that represents a 'generic' URI, as per RFC 2396. Consists of @@ -74,6 +74,8 @@ private final int defaultPort; private final String password; private final int port; + private static final char[] USERNAME_RESERVED = { ':', '@' }; + private static final char[] PASSWORD_RESERVED = { '@' }; protected GenericFileName( final String scheme, final String hostName, @@ -196,7 +198,6 @@ name.delete( 0, 2 ); // Extract userinfo, and split into username and password - // TODO - need to decode username and password final String userInfo = extractUserInfo( name ); final String userName; final String password; @@ -219,8 +220,8 @@ userName = null; password = null; } - auth.userName = userName; - auth.password = password; + auth.userName = UriParser.decode( userName ); + auth.password = UriParser.decode( password ); // Extract hostname, and normalise (lowercase) final String hostName = extractHostName( name ); @@ -340,12 +341,11 @@ buffer.append( "://" ); if ( userName != null && userName.length() != 0 ) { - // TODO - need to encode username and password - buffer.append( userName ); + UriParser.appendEncoded( buffer, userName, USERNAME_RESERVED ); if ( password != null && password.length() != 0 ) { buffer.append( ':' ); - buffer.append( password ); + UriParser.appendEncoded( buffer, password, PASSWORD_RESERVED ); } buffer.append( '@' ); } 1.15 +4 -0 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/UriParser.java Index: UriParser.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/UriParser.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- UriParser.java 12 Feb 2003 07:56:13 -0000 1.14 +++ UriParser.java 24 Jun 2003 10:38:16 -0000 1.15 @@ -314,6 +314,10 @@ public static String decode( final String encodedStr ) throws FileSystemException { + if ( encodedStr == null ) + { + return null; + } final StringBuffer buffer = new StringBuffer( encodedStr ); decode( buffer, 0, buffer.length() ); return buffer.toString(); 1.2 +12 -1 jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/test/GenericFileNameTestCase.java Index: GenericFileNameTestCase.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/test/GenericFileNameTestCase.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- GenericFileNameTestCase.java 15 Feb 2003 00:15:19 -0000 1.1 +++ GenericFileNameTestCase.java 24 Jun 2003 10:38:16 -0000 1.2 @@ -128,6 +128,17 @@ assertEquals( "/file", name.getPath() ); assertEquals( "ftp://user:[EMAIL PROTECTED]/", name.getRootURI() ); assertEquals( "ftp://user:[EMAIL PROTECTED]/file", name.getURI() ); + + // Encoded username and password + name = GenericFileName.parseUri( "ftp://%75ser%3A:[EMAIL PROTECTED]", 21 ); + assertEquals( "ftp", name.getScheme() ); + assertEquals( "user:", name.getUserName() ); + assertEquals( "@", name.getPassword() ); + assertEquals( "hostname", name.getHostName() ); + assertEquals( 21, name.getPort() ); + assertEquals( "/", name.getPath() ); + assertEquals( "ftp://user%3a:[EMAIL PROTECTED]/", name.getRootURI() ); + assertEquals( "ftp://user%3a:[EMAIL PROTECTED]/", name.getURI() ); } /**
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]