You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2003/05/19 17:55:23 UTC

cvs commit: ant/src/testcases/org/apache/tools/ant/util FileUtilsTest.java

bodewig     2003/05/19 08:55:23

  Modified:    src/main/org/apache/tools/ant/util FileUtils.java
               src/testcases/org/apache/tools/ant/util FileUtilsTest.java
  Log:
  removeLeadingPath didn't work as expected when trying to remove a path
  from itself.
  PR: 19979
  
  Revision  Changes    Path
  1.42      +8 -4      ant/src/main/org/apache/tools/ant/util/FileUtils.java
  
  Index: FileUtils.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/util/FileUtils.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- FileUtils.java	22 Apr 2003 18:23:55 -0000	1.41
  +++ FileUtils.java	19 May 2003 15:55:22 -0000	1.42
  @@ -988,12 +988,16 @@
        * @since Ant 1.5
        */
       public String removeLeadingPath(File leading, File path) {
  +        String l = normalize(leading.getAbsolutePath()).getAbsolutePath();
  +        String p = normalize(path.getAbsolutePath()).getAbsolutePath();
  +        if (l.equals(p)) {
  +            return "";
  +        }
  +
           // if leading's path ends with a slash, it will be stripped by
           // normalize - we always add one so we never think /foo was a
           // parent directory of /foobar
  -        String l = normalize(leading.getAbsolutePath()).getAbsolutePath()
  -            + File.separator;
  -        String p = normalize(path.getAbsolutePath()).getAbsolutePath();
  +        l += File.separator;
           if (p.startsWith(l)) {
               return p.substring(l.length());
           } else {
  
  
  
  1.16      +10 -1     ant/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java
  
  Index: FileUtilsTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- FileUtilsTest.java	7 Mar 2003 11:23:14 -0000	1.15
  +++ FileUtilsTest.java	19 May 2003 15:55:23 -0000	1.16
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -406,6 +406,15 @@
                        fu.removeLeadingPath(new File("/foo"), new File("/bar")));
           assertEquals(fu.normalize("/foobar").getAbsolutePath(), 
                        fu.removeLeadingPath(new File("/foo"), new File("/foobar")));
  +        // bugzilla report 19979
  +        assertEquals("", fu.removeLeadingPath(new File("/foo/bar"), 
  +                                              new File("/foo/bar")));
  +        assertEquals("", fu.removeLeadingPath(new File("/foo/bar"), 
  +                                              new File("/foo/bar/")));
  +        assertEquals("", fu.removeLeadingPath(new File("/foo/bar/"), 
  +                                              new File("/foo/bar/")));
  +        assertEquals("", fu.removeLeadingPath(new File("/foo/bar/"), 
  +                                              new File("/foo/bar")));
       }
   
       /**