Bug 37268 - mkdir task parses path incorrectly when it includes "../" - Fix included.
mkdir task parses path incorrectly when it includes "../" - Fix included.
Status: RESOLVED WORKSFORME
Product: Ant
Classification: Unclassified
Component: Core tasks
1.6.5
All Linux
: P2 blocker (vote)
: ---
Assigned To: Ant Notifications List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2005-10-27 15:28 UTC by Levent Guendogdu
Modified: 2008-02-22 12:18 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Levent Guendogdu 2005-10-27 15:28:08 UTC
When a mkdir task contains ".." as directory name, it will not be parsed
correctly. Same thing as it happened with Bug #26765. The fix is similar: call
the FiltUtils.normalize() to make sure the path is parsed correctly. Patch included.

diff -Nurb apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/Mkdir.java
apache-ant-1.6.5-fixed/src/main/org/apache/tools/ant/taskdefs/Mkdir.java
--- apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/Mkdir.java 
2005-06-02 15:19:58.000000000 +0200
+++ apache-ant-1.6.5-fixed/src/main/org/apache/tools/ant/taskdefs/Mkdir.java   
2005-10-27 15:26:50.000000000 +0200
@@ -20,6 +20,7 @@
 import java.io.File;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Task;
+import org.apache.tools.ant.util.FileUtils;

 /**
  * Creates a given directory.
@@ -34,6 +35,7 @@
 public class Mkdir extends Task {

     private static final int MKDIR_RETRY_SLEEP_MILLIS = 10;
+    private static final FileUtils fileUtils = FileUtils.getFileUtils();
     /**
      * our little directory
      */
@@ -48,6 +50,9 @@
             throw new BuildException("dir attribute is required", getLocation());
         }

+       // Normalize file name to make sure ".." are resolved correctly.
+       dir = fileUtils.normalize(dir.getAbsolutePath());
+
         if (dir.isFile()) {
             throw new BuildException("Unable to create directory as a file "
                                      + "already exists with that name: "
Comment 1 Stefan Bodewig 2006-01-28 15:45:07 UTC
dir will already be normalized, this happens when Ant translates the string from
dir="..." to the File instance passed to setDir.

I can't see any problem with

stefan@www:~/ASF/ant/ant-HEAD> cat test.xml
<project basedir="..">
  <mkdir dir="ant-HEAD/../../foo"/>
</project>
stefan@www:~/ASF/ant/ant-HEAD> ant -f test.xml
Buildfile: test.xml
    [mkdir] Created dir: /home/stefan/ASF/foo

BUILD SUCCESSFUL
Total time: 1 second