You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2019/01/30 15:43:55 UTC

[camel-k] branch master updated: Fixed array index out of boun that would kill camel-k operator in case of a malformed --dependency

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

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/master by this push:
     new 4f1e9a3  Fixed array index out of boun that would kill camel-k operator in case of a malformed --dependency
     new 92328ab  Merge pull request #396 from valdar/fixParseGAV
4f1e9a3 is described below

commit 4f1e9a37f896d3061de8adcb9e9d6d90a850b6e1
Author: Andrea Tarocchi <at...@redhat.com>
AuthorDate: Wed Jan 30 15:23:54 2019 +0100

    Fixed array index out of boun that would kill camel-k operator in case of a malformed --dependency
---
 pkg/util/maven/maven.go      |  8 ++++++++
 pkg/util/maven/maven_test.go | 15 +++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/pkg/util/maven/maven.go b/pkg/util/maven/maven.go
index cb8db2d..4e753cc 100644
--- a/pkg/util/maven/maven.go
+++ b/pkg/util/maven/maven.go
@@ -20,6 +20,8 @@ package maven
 import (
 	"bytes"
 	"encoding/xml"
+	"fmt"
+	"github.com/pkg/errors"
 	"os"
 	"os/exec"
 	"regexp"
@@ -100,6 +102,12 @@ func ParseGAV(gav string) (Dependency, error) {
 	rex := regexp.MustCompile("([^: ]+):([^: ]+)(:([^: ]*)(:([^: ]+))?)?(:([^: ]+))?")
 	res := rex.FindStringSubmatch(gav)
 
+	fmt.Println(res, len(res))
+
+	if res == nil || len(res) < 9 {
+		return Dependency{}, errors.New("GAV must match <groupId>:<artifactId>[:<packagingType>[:<classifier>]]:(<version>|'?')")
+	}
+
 	dep.GroupID = res[1]
 	dep.ArtifactID = res[2]
 	dep.Type = "jar"
diff --git a/pkg/util/maven/maven_test.go b/pkg/util/maven/maven_test.go
index fe71725..c09485c 100644
--- a/pkg/util/maven/maven_test.go
+++ b/pkg/util/maven/maven_test.go
@@ -182,6 +182,21 @@ func TestParseGAVWithClassifierAndType(t *testing.T) {
 	assert.Equal(t, dep.Classifier, "test")
 }
 
+func TestParseGAVMvnNoVersion(t *testing.T) {
+	dep, err := ParseGAV("mvn:org.apache.camel/camel-core")
+
+	assert.Nil(t, err)
+	assert.Equal(t, dep.GroupID, "mvn")
+	assert.Equal(t, dep.ArtifactID, "org.apache.camel/camel-core")
+}
+
+func TestParseGAVErrorNoColumn(t *testing.T) {
+	dep, err := ParseGAV("org.apache.camel.k.camel-k-runtime-noop-0.2.1-SNAPSHOT.jar")
+
+	assert.EqualError(t, err, "GAV must match <groupId>:<artifactId>[:<packagingType>[:<classifier>]]:(<version>|'?')")
+	assert.Equal(t, Dependency{}, dep)
+}
+
 func TestNewRepository(t *testing.T) {
 	r := NewRepository("http://nexus/public")
 	assert.Equal(t, "", r.ID)