This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/maven-remote-resources-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new 6bcbdf6  Consistent resource-bundle descriptor validation (#272) (#286)
6bcbdf6 is described below

commit 6bcbdf6338179c4d1fa4d3fb16370d2db1a3a905
Author: Elliotte Rusty Harold <[email protected]>
AuthorDate: Wed Oct 28 14:36:08 2026 +0000

    Consistent resource-bundle descriptor validation (#272) (#286)
    
    * Reject malformed resource bundle descriptors consistently in validate() 
(#272)
    
    * Update exception message assertion in RemoteResourcesMojoTest
    
    Co-authored-by: Copilot Autofix powered by AI 
<[email protected]>
    
    * Address Copilot review: handle empty optional segments and use split limit
    
    * Apply Spotless formatting
    
    * Match the validation message in 
testValidateRejectsDescriptorWithEmptySegment
    
    ---------
    
    Co-authored-by: Copilot Autofix powered by AI 
<[email protected]>
    Co-authored-by: Sylwester Lachiewicz <[email protected]>
---
 .../remote/AbstractProcessRemoteResourcesMojo.java         | 14 +++++++++++---
 .../plugin/resources/remote/RemoteResourcesMojoTest.java   | 13 +++++++++++++
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git 
a/src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java
 
b/src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java
index b848a35..571ab49 100644
--- 
a/src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java
+++ 
b/src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java
@@ -777,9 +777,17 @@ public abstract class AbstractProcessRemoteResourcesMojo 
extends AbstractMojo {
         for (String artifactDescriptor : resourceBundles) {
             // groupId:artifactId:version, groupId:artifactId:version:type
             // or groupId:artifactId:version:type:classifier
-            String[] s = StringUtils.split(artifactDescriptor, ":");
-
-            if (s.length < 3 || s.length > 5) {
+            // use the same splitting as downloadBundles() so both are 
consistent;
+            // also reject empty groupId/artifactId/version (e.g. a missing 
segment)
+            String[] s = artifactDescriptor.split(":", -1);
+
+            if (s.length < 3
+                    || s.length > 5
+                    || s[0].isEmpty()
+                    || s[1].isEmpty()
+                    || s[2].isEmpty()
+                    || (s.length >= 4 && s[3].isEmpty())
+                    || (s.length == 5 && s[4].isEmpty())) {
                 String position;
 
                 if (bundleCount == 1) {
diff --git 
a/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java
 
b/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java
index bbdbed6..60ddac8 100644
--- 
a/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java
+++ 
b/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java
@@ -463,6 +463,19 @@ public class RemoteResourcesMojoTest extends 
AbstractMojoTestCase {
         assertTrue(data.contains("rules"));
     }
 
+    public void testValidateRejectsDescriptorWithEmptySegment() throws 
Exception {
+        final MavenProjectResourcesStub project = 
createTestProject("default-validate");
+        final ProcessRemoteResourcesMojo mojo =
+                lookupProcessMojoWithSettings(project, new String[] 
{"org.example:dep::jar"});
+
+        try {
+            mojo.validate();
+            fail("Expected validate() to reject a resource bundle descriptor 
with a missing version");
+        } catch (MojoExecutionException e) {
+            assertTrue(e.getMessage().contains("must specify a groupId, 
artifactId"));
+        }
+    }
+
     protected void buildResourceBundle(String id, String sourceEncoding, 
String[] resourceNames, File jarName)
             throws Exception {
         final MavenProjectResourcesStub project = createTestProject(id);

Reply via email to