Skip to content

Commit

Permalink
Improve handling of the empty corpus case
Browse files Browse the repository at this point in the history
  • Loading branch information
korfuri committed Jul 12, 2017
1 parent 51e6c03 commit 9345b6c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions corpus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions corpus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 9345b6c

Please sign in to comment.