go-git icon indicating copy to clipboard operation
go-git copied to clipboard

plumbing: gitattributes, Avoid index out of range

Open To1ne opened this issue 3 years ago • 1 comments

When a path is deeper than the single asterisk pattern the code would crash with a "index out of range".

This change checks the length of the remaining pattern before it references an element of that slice.

With a single trailing asterisk paths deeper than the pattern should not get the attributes.

For example with the following .gitattributes file:

thirdparty/* linguist-vendored

This is how git handles it:

$ git check-attr --all thirdparty/README.md

thirdparty/README.md: diff: markdown
thirdparty/README.md: linguist-vendored: set

$ git check-attr --all thirdparty/package/README.md

thirdparty/package/README.md: diff: markdown

To1ne avatar Oct 12 '22 15:10 To1ne

@mcuadros Would you consider this small bug fix?

To1ne avatar Oct 12 '22 15:10 To1ne

Good catch, thank you for the contribution!

erizocosmico avatar Nov 07 '22 16:11 erizocosmico