You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wagon-commits@maven.apache.org by br...@apache.org on 2009/02/19 06:39:45 UTC
svn commit: r745740 - in /maven/wagon/trunk/wagon-provider-api/src:
main/java/org/apache/maven/wagon/PathUtils.java
test/java/org/apache/maven/wagon/PathUtilsTest.java
Author: brett
Date: Thu Feb 19 05:39:45 2009
New Revision: 745740
URL: http://svn.apache.org/viewvc?rev=745740&view=rev
Log:
[WAGON-231] PathUtils.toRelative() throws SIOOBE if supplied arguments specify the same directory
Submitted by: Benjamin Bentmann
Modified:
maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/PathUtils.java
maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/PathUtilsTest.java
Modified: maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/PathUtils.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/PathUtils.java?rev=745740&r1=745739&r2=745740&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/PathUtils.java (original)
+++ maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/PathUtils.java Thu Feb 19 05:39:45 2009
@@ -221,7 +221,7 @@
/**
* @param url
- * @return
+ * @return the port or {@link WagonConstants#UNKNOWN_PORT} if not existent
*/
public static int port( String url )
{
@@ -440,7 +440,15 @@
if ( absolutePath.startsWith( basedirPath ) )
{
- relative = absolutePath.substring( basedirPath.length() + 1 );
+ relative = absolutePath.substring( basedirPath.length() );
+ if ( relative.startsWith( "/" ) )
+ {
+ relative = relative.substring( 1 );
+ }
+ if ( relative.length() <= 0 )
+ {
+ relative = ".";
+ }
}
else
{
Modified: maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/PathUtilsTest.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/PathUtilsTest.java?rev=745740&r1=745739&r2=745740&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/PathUtilsTest.java (original)
+++ maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/PathUtilsTest.java Thu Feb 19 05:39:45 2009
@@ -19,6 +19,8 @@
* under the License.
*/
+import java.io.File;
+
import junit.framework.TestCase;
/**
@@ -231,4 +233,22 @@
assertEquals( "/", PathUtils.basedir( "http://localhost/" ) );
}
+ public void testToRelative()
+ {
+ assertEquals( "dir", PathUtils.toRelative( new File( "/home/user" ).getAbsoluteFile(),
+ new File( "/home/user/dir" ).getAbsolutePath() ) );
+ assertEquals( "dir", PathUtils.toRelative( new File( "C:/home/user" ).getAbsoluteFile(),
+ new File( "C:/home/user/dir" ).getAbsolutePath() ) );
+
+ assertEquals( "dir/subdir", PathUtils.toRelative( new File( "/home/user" ).getAbsoluteFile(),
+ new File( "/home/user/dir/subdir" ).getAbsolutePath() ) );
+ assertEquals( "dir/subdir", PathUtils.toRelative( new File( "C:/home/user" ).getAbsoluteFile(),
+ new File( "C:/home/user/dir/subdir" ).getAbsolutePath() ) );
+
+ assertEquals( ".", PathUtils.toRelative( new File( "/home/user" ).getAbsoluteFile(),
+ new File( "/home/user" ).getAbsolutePath() ) );
+ assertEquals( ".", PathUtils.toRelative( new File( "C:/home/user" ).getAbsoluteFile(),
+ new File( "C:/home/user" ).getAbsolutePath() ) );
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: wagon-commits-unsubscribe@maven.apache.org
For additional commands, e-mail: wagon-commits-help@maven.apache.org