diff --git a/corpus.go b/corpus.go index dc37d95..5dfb830 100644 --- a/corpus.go +++ b/corpus.go @@ -22,6 +22,9 @@ func NewCorpus(basepath string) (Corpus, error) { // Contains returns whether the provided filepath exists under this // Corpus. func (c Corpus) Contains(fpath string) bool { + if string(c) == "" { + return false + } rel, err := filepath.Rel(string(c), fpath) if err != nil { return false diff --git a/corpus_test.go b/corpus_test.go index 5434304..311cda4 100644 --- a/corpus_test.go +++ b/corpus_test.go @@ -14,6 +14,8 @@ func TestContains(t *testing.T) { assert.False(t, goref.Corpus("/a/b/c").Contains("/a/b/d")) assert.False(t, goref.Corpus("/a/b/c").Contains("/")) assert.False(t, goref.Corpus("/a/b/c").Contains("/a/b/")) + assert.False(t, goref.Corpus("").Contains("/a/b")) + assert.False(t, goref.Corpus("").Contains("/a/b/")) } func TestRel(t *testing.T) {