Skip to content

Commit d4331a6

Browse files
ruhan1claude
andcommitted
Fix ArtifactPathInfo to reject non-standard paths
Add validation to ensure filenames follow Maven naming convention (artifactId-version-...) and reject paths where the regex matches but produces incorrect parsing results. This prevents mis-parsing of non-standard paths like RPM artifacts that don't conform to Maven layout. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent f8007c3 commit d4331a6

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

identities/src/main/java/org/commonjava/atlas/maven/ident/util/ArtifactPathInfo.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ public static ArtifactPathInfo parse( final String path )
8080
.replace( '/', '.' );
8181
final String a = matcher.group( ARTIFACT_ID_GROUP );
8282
final String v = matcher.group( VERSION_GROUP );
83+
final String f = matcher.group( FILE_GROUP );
84+
85+
// Validate that the filename follows standard Maven layout: {artifactId}-{version}-...
86+
// This prevents mis-parsing paths that match the regex pattern but don't follow Maven conventions
87+
String expectedPrefix = a + "-" + v;
88+
if ( !f.startsWith( expectedPrefix ) || f.contains( "/" ) )
89+
{
90+
return null;
91+
}
8392

8493
String c = "";
8594
String t = null;
@@ -131,8 +140,6 @@ public static ArtifactPathInfo parse( final String path )
131140
c = left.substring( 0, leftLen - extLen );
132141
}
133142

134-
final String f = matcher.group( FILE_GROUP );
135-
136143
if ( checksumType != null && CHECKSUM_TYPES.contains( checksumType ) )
137144
{
138145
t = t + checksumType;

identities/src/test/java/org/commonjava/atlas/maven/ident/util/ArtifactPathInfoTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,15 @@ public void matchCompoundExtTypes2(){
191191
assertThat( info.getType(), equalTo( "a.b.c" ) );
192192
}
193193

194+
@Test
195+
public void testNonStandardRpmPathReturnsNull()
196+
{
197+
// RPM path where filename doesn't follow Maven naming convention
198+
String path = "/org/jboss/pnc/rpm/org/hibernate/search/hibernate-search-integrationtest-jakarta-jb-eap-8.0-rhel-9/6.2.2.Final/eap8-hibernate-search-6.2.2-1.Final.1.el8.src.rpm";
199+
ArtifactPathInfo info = ArtifactPathInfo.parse( path );
200+
assertThat( info, equalTo( null ) );
201+
}
202+
194203
@Test
195204
public void testChecksumTypes()
196205
{

0 commit comments

Comments
 (0)