Skip to content

Commit

Permalink
Merge pull request #396 from valdar/fixParseGAV
Browse files Browse the repository at this point in the history
Fixed array index out of boun that would kill camel-k operator in case of a malformed --dependency
  • Loading branch information
oscerd authored Jan 30, 2019
2 parents cdbc09d + 4f1e9a3 commit 92328ab
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/util/maven/maven.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package maven
import (
"bytes"
"encoding/xml"
"fmt"
"github.com/pkg/errors"
"os"
"os/exec"
"regexp"
Expand Down Expand Up @@ -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"
Expand Down
15 changes: 15 additions & 0 deletions pkg/util/maven/maven_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 92328ab

Please sign in to comment.