Author: xavier
Date: Fri Feb 29 05:05:33 2008
New Revision: 632310

URL: http://svn.apache.org/viewvc?rev=632310&view=rev
Log:
FIX: Cachefileset task silently fails with parent dir ".." construct (IVY-638)

Added:
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/CacheUtil.java   
(with props)
    ant/ivy/core/trunk/test/repositories/ivysettings-invalidcachepattern.xml   
(with props)
Modified:
    ant/ivy/core/trunk/CHANGES.txt
    
ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java
    ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyCacheFilesetTest.java

Modified: ant/ivy/core/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=632310&r1=632309&r2=632310&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Fri Feb 29 05:05:33 2008
@@ -66,6 +66,7 @@
 =====================================
 - FIX: PublishEventsTest fails when Ivy sources are located in a directory 
with a + (IVY-755)
 - FIX: XML entity parsing does not work properly (IVY-737) (thanks to Patrick 
Woodworth)
+- FIX: Cachefileset task silently fails with parent dir ".." construct 
(IVY-638)
 
    2.0.0-beta2
 =====================================

Added: ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/CacheUtil.java
URL: 
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/CacheUtil.java?rev=632310&view=auto
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/CacheUtil.java (added)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/CacheUtil.java Fri 
Feb 29 05:05:33 2008
@@ -0,0 +1,50 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.ivy.core.cache;
+
+/**
+ * Utility class providing some cache related facilities. 
+ *
+ */
+public final class CacheUtil {
+
+    /**
+     * Checks that the given pattern is acceptable as a cache pattern
+     * 
+     * @param cachePattern
+     *            the pattern to check
+     * @throws IllegalArgumentException
+     *             if the pattern isn't acceptable as cache pattern
+     */
+    public static void checkCachePattern(String cachePattern) {
+        if (cachePattern == null) {
+            throw new IllegalArgumentException("null cache pattern not 
allowed.");
+        }
+        if (cachePattern.startsWith("..")) {
+            throw new IllegalArgumentException("invalid cache pattern: '" + 
cachePattern 
+                + "': cache patterns must not lead outside cache directory");
+        }
+        if (cachePattern.startsWith("/")) {
+            throw new IllegalArgumentException("invalid cache pattern: '" + 
cachePattern 
+                + "': cache patterns must not be absolute");
+        }
+    }
+
+    private CacheUtil() {
+    }
+}

Propchange: ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/CacheUtil.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
URL: 
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java?rev=632310&r1=632309&r2=632310&view=diff
==============================================================================
--- 
ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
 (original)
+++ 
ant/ivy/core/trunk/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java
 Fri Feb 29 05:05:33 2008
@@ -144,6 +144,7 @@
     }
 
     public void setArtifactPattern(String artifactPattern) {
+        CacheUtil.checkCachePattern(artifactPattern);
         this.artifactPattern = artifactPattern;
     }
 
@@ -178,10 +179,12 @@
     }
 
     public void setDataFilePattern(String dataFilePattern) {
+        CacheUtil.checkCachePattern(dataFilePattern);
         this.dataFilePattern = dataFilePattern;
     }
 
     public void setIvyPattern(String ivyPattern) {
+        CacheUtil.checkCachePattern(ivyPattern);
         this.ivyPattern = ivyPattern;
     }
 

Modified: 
ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java
URL: 
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java?rev=632310&r1=632309&r2=632310&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java 
(original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java 
Fri Feb 29 05:05:33 2008
@@ -39,6 +39,7 @@
 import org.apache.ivy.core.IvyPatternHelper;
 import org.apache.ivy.core.NormalRelativeUrlResolver;
 import org.apache.ivy.core.RelativeUrlResolver;
+import org.apache.ivy.core.cache.CacheUtil;
 import org.apache.ivy.core.cache.DefaultRepositoryCacheManager;
 import org.apache.ivy.core.cache.DefaultResolutionCacheManager;
 import org.apache.ivy.core.cache.RepositoryCacheManager;
@@ -1278,6 +1279,7 @@
     }
 
     public void setDefaultCacheIvyPattern(String defaultCacheIvyPattern) {
+        CacheUtil.checkCachePattern(defaultCacheIvyPattern);
         this.defaultCacheIvyPattern = defaultCacheIvyPattern;
     }
     
@@ -1286,6 +1288,7 @@
     }
 
     public void setDefaultCacheArtifactPattern(String 
defaultCacheArtifactPattern) {
+        CacheUtil.checkCachePattern(defaultCacheIvyPattern);
         this.defaultCacheArtifactPattern = defaultCacheArtifactPattern;
     }
     

Modified: 
ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyCacheFilesetTest.java
URL: 
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyCacheFilesetTest.java?rev=632310&r1=632309&r2=632310&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyCacheFilesetTest.java 
(original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyCacheFilesetTest.java 
Fri Feb 29 05:05:33 2008
@@ -112,6 +112,19 @@
         }
     }
 
+    public void testInvalidPattern() throws Exception {
+        try {
+            project.setProperty("ivy.settings.file", 
+                "test/repositories/ivysettings-invalidcachepattern.xml");
+            project.setProperty("ivy.dep.file", 
"test/java/org/apache/ivy/ant/ivy-simple.xml");
+            fileset.setSetid("simple-setid");
+            fileset.execute();
+            fail("failure didn't raised an exception with default 
haltonfailure setting");
+        } catch (BuildException ex) {
+            // ok => should raise an exception
+        }
+    }
+
     public void testHaltOnFailure() throws Exception {
         try {
             project.setProperty("ivy.dep.file", 
"test/java/org/apache/ivy/ant/ivy-failure.xml");

Added: ant/ivy/core/trunk/test/repositories/ivysettings-invalidcachepattern.xml
URL: 
http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/repositories/ivysettings-invalidcachepattern.xml?rev=632310&view=auto
==============================================================================
--- ant/ivy/core/trunk/test/repositories/ivysettings-invalidcachepattern.xml 
(added)
+++ ant/ivy/core/trunk/test/repositories/ivysettings-invalidcachepattern.xml 
Fri Feb 29 05:05:33 2008
@@ -0,0 +1,46 @@
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   KIND, either express or implied.  See the License for the
+   specific language governing permissions and limitations
+   under the License.    
+-->
+<ivysettings>
+       <properties file="${ivy.settings.dir}/ivysettings.properties" />
+       <settings defaultResolver="test"/>
+       <caches defaultCacheDir="${cache.dir}"  
+               ivyPattern="../[module]/ivy-[revision].xml">
+       </caches>
+       <resolvers>
+               <chain name="test">
+                       <filesystem name="1">
+                               <ivy 
pattern="${ivy.settings.dir}/1/[organisation]/[module]/ivys/ivy-[revision].xml"/>
+                               <artifact 
pattern="${ivy.settings.dir}/1/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]"/>
+                       </filesystem>
+                       <dual name="2">
+                               <filesystem name="2-ivy">
+                                       <ivy 
pattern="${ivy.settings.dir}/2/[module]/ivy-[revision].xml"/>
+                               </filesystem>
+                               <filesystem name="2-artifact">
+                                       <artifact 
pattern="${ivy.settings.dir}/2/[module]/[artifact]-[revision].[ext]"/>
+                                       <artifact 
pattern="${ivy.settings.dir}/2/[module]/[artifact].[ext]"/>
+                               </filesystem>
+                       </dual>
+               </chain>
+               <filesystem name="install">
+                       <ivy 
pattern="build/test/install/[organisation]/[module]/[artifact]-[revision].[ext]"/>
+                       <artifact 
pattern="build/test/install/[organisation]/[module]/[artifact]-[revision].[ext]"/>
+               </filesystem>
+       </resolvers>
+</ivysettings>

Propchange: 
ant/ivy/core/trunk/test/repositories/ivysettings-invalidcachepattern.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain


Reply via email to