>From the same commit.

==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/utils/PathUtilTest.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-common/src/test/java/org/apache/maven/archiva/common/utils/PathUtilTest.java Sat Aug 25 20:16:11 2007
@@ -34,9 +34,15 @@
 public class PathUtilTest
     extends TestCase
 {
-    public void testToRelative()
+    public void testToRelativeWithoutSlash()
     {
         assertEquals( "path/to/resource.xml", PathUtil.getRelative( "/home/user/foo/repository",
+                                                                    "/home/user/foo/repository/path/to/resource.xml" ) );
+    }
+    
+    public void testToRelativeWithSlash()
+    {
+        assertEquals( "path/to/resource.xml", PathUtil.getRelative( "/home/user/foo/repository/",
                                                                     "/home/user/foo/repository/path/to/resource.xml" ) );
     }

I thought those test names would have been sufficient. ;-)
When you pass in (as argument 1) a path that has a slash at the end, with the old code, the relative path would be wrong.

Example of original bug.

PathUtil.getRelative("/home/user/foo/repository/", "/home/user/foo/repository/path/to/resource.xml") would have returned "ath/to/resource.xml"
/* notice the missing "p" in "path"? */

- Joakim



Brett Porter wrote:
And/or a comment in the test case would be a good way to identify it. I need to learn to write those more.

On 30/08/2007, at 2:17 PM, Wendy Smoak wrote:

Joakim, can you do me a favor and explain what the bug was?  I read
commit messages from lots of projects, and it's helpful to see the
problem and fix described in the commit message, and then see the
actual solution in the code.  I'm sure I'm not alone. :)

-- 
Wendy

On 8/25/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
Author: joakime
Date: Sat Aug 25 20:16:11 2007
New Revision: 569758

URL: http://svn.apache.org/viewvc?rev=569758&view=rev
Log:
Fixing subtle bug in PathUtil.toRelative() encountered during Metadata work.


Reply via email to