aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Erdfelt <joakime@apache.org>2007-10-24 00:00:30 +0000
committerJoakim Erdfelt <joakime@apache.org>2007-10-24 00:00:30 +0000
commit89079a268431bc8b8a9035449982cabe1e21f9ca (patch)
tree6d660cc50d79ae2f33daafb5c4c86ff796a82a81
parentac7babe5a1d3e5cf1798dd3c1948811759e0e924 (diff)
downloadarchiva-89079a268431bc8b8a9035449982cabe1e21f9ca.tar.gz
archiva-89079a268431bc8b8a9035449982cabe1e21f9ca.zip
Adding some tests for invalid request paths.
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@587701 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java25
-rw-r--r--archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java4
2 files changed, 24 insertions, 5 deletions
diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java
index 12158586b..7a67cf75f 100644
--- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java
+++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/RepositoryRequest.java
@@ -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
{
diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java
index 0d4cfa791..2a3de5a51 100644
--- a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java
+++ b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/content/RepositoryRequestTest.java
@@ -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
{