Skip to content

Parser panics on line containing just whitespace #2

@bradleyjkemp

Description

@bradleyjkemp

Hi, just ran into a bug where lines that only contain whitespace cause a panic in the parser. This is quite a tricky one to diagnose because such lines are very hard to spot.

Reproduction:

package main

import "github.com/denormal/go-gitignore"

func main() {
	// or match against a repository
	//  - here we match a directory path relative to the repository
	matcher, err := gitignore.NewRepository( "/tmp/panic" )
	if err != nil {
		panic(err)
	}

	matcher.Relative("panic_test", false)
}

Panics if the file /tmp/panic/.gitignore contains a line with a single space e.g.

# Next line contains just whitespace
 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions