diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2022-11-07 17:03:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-07 17:03:35 +0100 |
commit | 1a0530e03cdcac6af61f064e180685cf2aec2802 (patch) | |
tree | c548e89bae59426851ccf1830cbea574bfe2fa86 /plumbing | |
parent | f37bb587b6634435afb5069b2101cb4e0ff78d63 (diff) | |
parent | 7dd5d8f39a3c31c8257c29a8cfa4ef2cf15d4a80 (diff) | |
download | go-git-1a0530e03cdcac6af61f064e180685cf2aec2802.tar.gz |
Merge pull request #598 from To1ne/toon-fix-gitattr-crash
plumbing: gitattributes, Avoid index out of range
Diffstat (limited to 'plumbing')
-rw-r--r-- | plumbing/format/gitattributes/pattern.go | 5 | ||||
-rw-r--r-- | plumbing/format/gitattributes/pattern_test.go | 6 |
2 files changed, 11 insertions, 0 deletions
diff --git a/plumbing/format/gitattributes/pattern.go b/plumbing/format/gitattributes/pattern.go index d961aba..f101f47 100644 --- a/plumbing/format/gitattributes/pattern.go +++ b/plumbing/format/gitattributes/pattern.go @@ -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:] diff --git a/plumbing/format/gitattributes/pattern_test.go b/plumbing/format/gitattributes/pattern_test.go index f95be6e..981d56f 100644 --- a/plumbing/format/gitattributes/pattern_test.go +++ b/plumbing/format/gitattributes/pattern_test.go @@ -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"}) |