Skip to content

Commit

Permalink
Fixing dictionary detection for absolute paths
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanoj3 committed Jul 8, 2019
1 parent cca80a0 commit e3261c8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 1 addition & 3 deletions pkg/dictionary/dictionary.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"io"
"net/http"
"net/url"
"os"

"github.com/pkg/errors"
Expand All @@ -13,8 +12,7 @@ import (
const commentPrefix = "#"

func NewDictionaryFrom(path string, doer Doer) ([]string, error) {
_, err := url.ParseRequestURI(path)
if err != nil {
if _, err := os.Stat(path); !os.IsNotExist(err) {
return newDictionaryFromLocalFile(path)
}

Expand Down
18 changes: 18 additions & 0 deletions pkg/dictionary/dictionary_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dictionary_test
import (
"net/http"
"net/http/httptest"
"path/filepath"
"testing"
"time"

Expand All @@ -22,6 +23,21 @@ func TestDictionaryFromFile(t *testing.T) {
assert.Equal(t, expectedValue, entries)
}

func TestDictionaryFromAbsolutePath(t *testing.T) {
path, err := filepath.Abs("testdata/dict.txt")
assert.NoError(t, err)

entries, err := dictionary.NewDictionaryFrom(path, &http.Client{})
assert.NoError(t, err)

expectedValue := []string{
"home",
"home/index.php",
"blabla",
}
assert.Equal(t, expectedValue, entries)
}

func TestDictionaryFromFileWithInvalidPath(t *testing.T) {
t.Parallel()

Expand All @@ -37,6 +53,7 @@ func TestNewDictionaryFromRemoteFile(t *testing.T) {
/about
/contacts
something
potato
`
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(dict))
Expand All @@ -52,6 +69,7 @@ something
"/about",
"/contacts",
"something",
"potato",
}
assert.Equal(t, expectedValue, entries)
}
Expand Down

0 comments on commit e3261c8

Please sign in to comment.