summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-12-28 11:32:02 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-12-28 11:32:02 +0100
commit1b0780dbebb912a8e86487fc3573c687e0b5171f (patch)
tree721e93d54507586a60c5b4c0e8b6e0fc881eb64f /source
parent3cdf19e9b7e46c57a9bb43ff02199177feb55768 (diff)
source: Make sure .File.Dir() ends with a slash
Updates #4190
Diffstat (limited to 'source')
-rw-r--r--source/fileInfo.go5
-rw-r--r--source/fileInfo_test.go22
2 files changed, 26 insertions, 1 deletions
diff --git a/source/fileInfo.go b/source/fileInfo.go
index e4b4a80fb..a20ba27e5 100644
--- a/source/fileInfo.go
+++ b/source/fileInfo.go
@@ -162,9 +162,12 @@ func (fi *FileInfo) init() {
}
func (sp *SourceSpec) NewFileInfo(baseDir, filename string, fi os.FileInfo) *FileInfo {
+
dir, name := filepath.Split(filename)
+ if !strings.HasSuffix(dir, helpers.FilePathSeparator) {
+ dir = dir + helpers.FilePathSeparator
+ }
- dir = strings.TrimSuffix(dir, helpers.FilePathSeparator)
baseDir = strings.TrimSuffix(baseDir, helpers.FilePathSeparator)
relDir := ""
diff --git a/source/fileInfo_test.go b/source/fileInfo_test.go
index 3f99497ad..1d7c86ec2 100644
--- a/source/fileInfo_test.go
+++ b/source/fileInfo_test.go
@@ -14,9 +14,31 @@
package source
import (
+ "path/filepath"
"testing"
+
+ "github.com/stretchr/testify/require"
)
func TestFileInfo(t *testing.T) {
+ assert := require.New(t)
+
+ s := newTestSourceSpec()
+
+ for _, this := range []struct {
+ base string
+ filename string
+ assert func(f *FileInfo)
+ }{
+ {"/a/", filepath.FromSlash("/a/b/page.md"), func(f *FileInfo) {
+ assert.Equal(filepath.FromSlash("/a/b/page.md"), f.Filename())
+ assert.Equal(filepath.FromSlash("b/"), f.Dir())
+ assert.Equal(filepath.FromSlash("b/page.md"), f.Path())
+
+ }},
+ } {
+ f := s.NewFileInfo(this.base, this.filename, nil)
+ this.assert(f)
+ }
}