Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: Slice index out of range with / pattern in .gitignore files #5

Open
boyter opened this issue Jan 19, 2020 · 0 comments
Open

Comments

@boyter
Copy link

boyter commented Jan 19, 2020

If go-gitignore is supplied with a gitignore that consists of a single character / then it will panic with the following,

panic: runtime error: slice bounds out of range [:1] with length 0

this is due to the following code inside inital_holder.go

func (h *initialPatternHolder) add(pattern string) {
	trimedPattern := strings.TrimPrefix(pattern, "/")

	if strings.IndexAny(trimedPattern[0:1], initials) != -1 {
		h.patterns.set(trimedPattern[0], newPatternForEqualizedPath(pattern))
	} else {
		h.otherPatterns.add(newPatternForEqualizedPath(pattern))
	}
}

Where the trimmed pattern is changed from / to empty string and then trimedPattern[0:1] tries to reference outside the string length.

Not sure what the resolution for this is? Should it ignore the pattern? Return an error? I am not familiar enough with the semantics of .gitignore files to comment sorry.

Relates to boyter/scc#149

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant