diff --git a/WHATSNEW b/WHATSNEW index b2f0f7b7d..6804fb391 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -229,6 +229,12 @@ Other changes: make the task fail the build if it tries to extract an empty archive. + * and have a new attribute stripAbsolutePathSpec. + When set to true, Ant will remove any leading path separator from + the archived entry's name before extracting it (making the name a + relative file name). + Bugzilla Report 28911. + Changes from Ant 1.7.0 TO Ant 1.7.1 ============================================= diff --git a/docs/manual/CoreTasks/unzip.html b/docs/manual/CoreTasks/unzip.html index b0d056b0e..32aad2f40 100644 --- a/docs/manual/CoreTasks/unzip.html +++ b/docs/manual/CoreTasks/unzip.html @@ -116,6 +116,15 @@ archive.

error. since Ant 1.8.0 No, defaults to false + + stripAbsolutePathSpec + whether Ant should remove leading '/' or '\' + characters from the extracted file name before extracing it. + Note that this changes the entry's name before applying + include/exclude patterns and before using the nested mappers (if + any). since Ant 1.8.0 + No, defaults to false +

Examples

diff --git a/src/main/org/apache/tools/ant/taskdefs/Expand.java b/src/main/org/apache/tools/ant/taskdefs/Expand.java
index 2e73d1cbe..bef0079d3 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Expand.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Expand.java
@@ -67,6 +67,7 @@ public class Expand extends Task {
     private Union resources = new Union();
     private boolean resourcesSpecified = false;
     private boolean failOnEmptyArchive = false;
+    private boolean stripAbsolutePathSpec = false;
 
     private static final String NATIVE_ENCODING = "native-encoding";
 
@@ -232,9 +233,19 @@ public class Expand extends Task {
                                boolean isDirectory, FileNameMapper mapper)
                                throws IOException {
 
+        if (stripAbsolutePathSpec && entryName.length() > 0
+            && (entryName.charAt(0) == File.separatorChar
+                || entryName.charAt(0) == '/'
+                || entryName.charAt(0) == '\\')) {
+            log("stripped absolute path spec from " + entryName,
+                Project.MSG_VERBOSE);
+            entryName = entryName.substring(1);
+        }
+
         if (patternsets != null && patternsets.size() > 0) {
             String name = entryName.replace('/', File.separatorChar)
                 .replace('\\', File.separatorChar);
+
             boolean included = false;
             Set includePatterns = new HashSet();
             Set excludePatterns = new HashSet();
@@ -432,4 +443,13 @@ public class Expand extends Task {
         this.encoding = encoding;
     }
 
+    /**
+     * Whether leading path separators should be stripped.
+     *
+     * @since Ant 1.8.0
+     */
+    public void setStripAbsolutePathSpec(boolean b) {
+        stripAbsolutePathSpec = b;
+    }
+
 }
diff --git a/src/tests/antunit/taskdefs/unzip-test.xml b/src/tests/antunit/taskdefs/unzip-test.xml
index f295038b7..0294a8c4b 100644
--- a/src/tests/antunit/taskdefs/unzip-test.xml
+++ b/src/tests/antunit/taskdefs/unzip-test.xml
@@ -36,4 +36,19 @@
       
     
   
+
+  
+  
+    
+    
+    
+    
+    
+    
+      
+    
+    
+    
+