]> source.dussan.org Git - archiva.git/commitdiff
Adding some tests for invalid request paths.
authorJoakim Erdfelt <joakime@apache.org>
Wed, 24 Oct 2007 00:00:30 +0000 (00:00 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Wed, 24 Oct 2007 00:00:30 +0000 (00:00 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@587701 13f79535-47bb-0310-9956-ffa450edef68

archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java
archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java

index 12158586b3daf618dc392fdd8b6d0e4b1de2806b..7a67cf75f696f06ce381df0d98de47898090bada 100644 (file)
@@ -99,13 +99,30 @@ public class RepositoryRequest
     public ArtifactReference toArtifactReference( String requestedPath )
         throws LayoutException
     {
-        if ( isDefault( requestedPath ) )
+        if ( StringUtils.isBlank( requestedPath ) )
+        {
+            throw new LayoutException( "Blank request path is not a valid." );
+        }
+        
+        String path = requestedPath;
+        while ( path.startsWith( "/" ) )
+        {
+            path = path.substring( 1 );
+
+            // Only slash? that's bad, mmm-kay?
+            if ( "/".equals( path ) )
+            {
+                throw new LayoutException( "Invalid request path: Slash only." );
+            }
+        }
+
+        if ( isDefault( path ) )
         {
-            return DefaultPathParser.toArtifactReference( requestedPath );
+            return DefaultPathParser.toArtifactReference( path );
         }
-        else if ( isLegacy( requestedPath ) )
+        else if ( isLegacy( path ) )
         {
-            return LegacyPathParser.toArtifactReference( requestedPath );
+            return LegacyPathParser.toArtifactReference( path );
         }
         else
         {
index 0d4cfa7919c42d331123d15b2b86aaf7060b3886..2a3de5a51a454c36b3a1398744f50a7f62cc6321 100644 (file)
@@ -127,8 +127,10 @@ public class RepositoryRequestTest
         throws Exception
     {
         assertValid( "org.apache.derby/poms/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", null, "pom" );
+        // Starting slash should not prevent detection.
+        assertValid( "/org.apache.derby/poms/derby-10.2.2.0.pom", "org.apache.derby", "derby", "10.2.2.0", null, "pom" );
     }
-
+    
     public void testValidDefaultDerbyPom()
         throws Exception
     {