Skip to content

Commit

Permalink
Merge pull request #598 from To1ne/toon-fix-gitattr-crash
Browse files Browse the repository at this point in the history
plumbing: gitattributes, Avoid index out of range
  • Loading branch information
mcuadros committed Nov 7, 2022
2 parents f37bb58 + 7dd5d8f commit 1a0530e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions plumbing/format/gitattributes/pattern.go
Expand Up @@ -52,6 +52,11 @@ func (p *pattern) Match(path []string) bool {
var match, doublestar bool
var err error
for _, part := range path {
// path is deeper than pattern
if len(pattern) == 0 {
return false
}

// skip empty
if pattern[0] == "" {
pattern = pattern[1:]
Expand Down
6 changes: 6 additions & 0 deletions plumbing/format/gitattributes/pattern_test.go
Expand Up @@ -174,6 +174,12 @@ func (s *PatternSuite) TestGlobMatch_tailingAsterisks_single(c *C) {
c.Assert(r, Equals, true)
}

func (s *PatternSuite) TestGlobMatch_tailingAsterisk_single(c *C) {
p := ParsePattern("/*lue/*", nil)
r := p.Match([]string{"value", "volcano", "tail"})
c.Assert(r, Equals, false)
}

func (s *PatternSuite) TestGlobMatch_tailingAsterisks_exactMatch(c *C) {
p := ParsePattern("/*lue/vol?ano/**", nil)
r := p.Match([]string{"value", "volcano"})
Expand Down

0 comments on commit 1a0530e

Please sign in to comment.