tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jkemn...@apache.org
Subject tapestry-5 git commit: TAP5-2448: Throw an IOException from the {{openStream}} method of a resource that references a directory inside a JAR file
Date Wed, 08 Apr 2015 12:35:39 GMT
Repository: tapestry-5
Updated Branches:
  refs/heads/master 3e36ee69c -> a1812d1b0


TAP5-2448: Throw an IOException from the {{openStream}} method of a resource that references
a directory inside a JAR file


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/a1812d1b
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/a1812d1b
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/a1812d1b

Branch: refs/heads/master
Commit: a1812d1b0fe0b3fefe4d80b4473101d5c9cec55f
Parents: 3e36ee6
Author: Jochen Kemnade <jochen.kemnade@eddyson.de>
Authored: Wed Apr 8 14:34:19 2015 +0200
Committer: Jochen Kemnade <jochen.kemnade@eddyson.de>
Committed: Wed Apr 8 14:34:19 2015 +0200

----------------------------------------------------------------------
 .../ioc/internal/util/AbstractResource.java          |  7 +++++++
 .../groovy/ioc/specs/ClasspathResourceSpec.groovy    | 15 +++++++++++++++
 2 files changed, 22 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1812d1b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/AbstractResource.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/AbstractResource.java
b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/AbstractResource.java
index b80e0f3..5f3d0fa 100644
--- a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/AbstractResource.java
+++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/AbstractResource.java
@@ -280,6 +280,13 @@ public abstract class AbstractResource extends LockSupport implements
Resource
         {
             return null;
         }
+        if ("jar".equals(url.getProtocol())){
+            // TAP5-2448: make sure that the URL does not reference a directory
+            if (new URL(url.toString() + "/") != null)
+            {
+                throw new IOException("Cannot open a steam for a resource that references
a directory inside a JAR file (" + url + ").");
+            }
+        }
 
         return new BufferedInputStream(url.openStream());
     }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a1812d1b/tapestry-ioc/src/test/groovy/ioc/specs/ClasspathResourceSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/ioc/specs/ClasspathResourceSpec.groovy b/tapestry-ioc/src/test/groovy/ioc/specs/ClasspathResourceSpec.groovy
index 8b17650..e3e4310 100644
--- a/tapestry-ioc/src/test/groovy/ioc/specs/ClasspathResourceSpec.groovy
+++ b/tapestry-ioc/src/test/groovy/ioc/specs/ClasspathResourceSpec.groovy
@@ -2,6 +2,8 @@ package ioc.specs
 
 import org.apache.commons.lang3.SystemUtils
 import org.apache.tapestry5.ioc.internal.util.ClasspathResource
+
+import spock.lang.Issue;
 import spock.lang.Specification
 
 class ClasspathResourceSpec extends Specification {
@@ -251,5 +253,18 @@ class ClasspathResourceSpec extends Specification {
 
         r.forFile("../foo/bar").toString() == "classpath:foo/bar"
     }
+    
+    @Issue('TAP5-2448')
+    def "Cannot open a stream for a directory resource within a JAR file"() {
+      setup:
+      ClasspathResource r = new ClasspathResource('org/slf4j/spi')
+      
+      when:
+      r.openStream()
+      
+      then:
+      IOException e = thrown()
+      e.message.contains 'Cannot open a steam for a resource that references a directory
inside a JAR file'
+    }
 
 }


Mime
View raw message