diff options
author | bep <bjorn.erik.pedersen@gmail.com> | 2014-12-07 21:48:00 +0300 |
---|---|---|
committer | spf13 <steve.francia@gmail.com> | 2014-12-09 17:43:15 +0300 |
commit | 9f77f93071d836a35b0078d1b349968abddb4a18 (patch) | |
tree | 909238a41b20b9e23324e4ffca01e8143655dd4a /target | |
parent | 3a8c12418a97230df714488e522f44ce8af685c5 (diff) |
Fix various Windows-issues
File handling was broken on Windows. This commit contains a revision of the path handling with separation of file paths and urls where needed.
There may be remaining issues and there may be better ways to do this, but it is easier to start that refactoring job with a set of passing tests.
Fixes #687
Fixes #660
Diffstat (limited to 'target')
-rw-r--r-- | target/alias_test.go | 13 | ||||
-rw-r--r-- | target/page.go | 2 | ||||
-rw-r--r-- | target/page_test.go | 14 |
3 files changed, 16 insertions, 13 deletions
diff --git a/target/alias_test.go b/target/alias_test.go index d19349f23..ec686af54 100644 --- a/target/alias_test.go +++ b/target/alias_test.go @@ -1,6 +1,7 @@ package target import ( + "path/filepath" "testing" ) @@ -13,14 +14,14 @@ func TestHTMLRedirectAlias(t *testing.T) { expected string }{ {"", ""}, - {"s", "s/index.html"}, - {"/", "/index.html"}, - {"alias 1", "alias-1/index.html"}, - {"alias 2/", "alias-2/index.html"}, + {"s", filepath.FromSlash("s/index.html")}, + {"/", filepath.FromSlash("/index.html")}, + {"alias 1", filepath.FromSlash("alias-1/index.html")}, + {"alias 2/", filepath.FromSlash("alias-2/index.html")}, {"alias 3.html", "alias-3.html"}, {"alias4.html", "alias4.html"}, - {"/alias 5.html", "/alias-5.html"}, - {"/трям.html", "/трям.html"}, + {"/alias 5.html", filepath.FromSlash("/alias-5.html")}, + {"/трям.html", filepath.FromSlash("/трям.html")}, } for _, test := range tests { diff --git a/target/page.go b/target/page.go index 924037402..b02e13925 100644 --- a/target/page.go +++ b/target/page.go @@ -32,7 +32,7 @@ func (pp *PagePub) Publish(path string, r io.Reader) (err error) { } func (pp *PagePub) Translate(src string) (dest string, err error) { - if src == "/" { + if src == helpers.FilePathSeparator { if pp.PublishDir != "" { return filepath.Join(pp.PublishDir, "index.html"), nil } diff --git a/target/page_test.go b/target/page_test.go index 69ad1cfa2..ab3b0f1ca 100644 --- a/target/page_test.go +++ b/target/page_test.go @@ -1,6 +1,7 @@ package target import ( + "path/filepath" "testing" ) @@ -24,13 +25,14 @@ func TestPageTranslator(t *testing.T) { for _, test := range tests { f := new(PagePub) - dest, err := f.Translate(test.content) + dest, err := f.Translate(filepath.FromSlash(test.content)) + expected := filepath.FromSlash(test.expected) if err != nil { t.Fatalf("Translate returned and unexpected err: %s", err) } - if dest != test.expected { - t.Errorf("Tranlate expected return: %s, got: %s", test.expected, dest) + if dest != expected { + t.Errorf("Translate expected return: %s, got: %s", expected, dest) } } } @@ -53,7 +55,7 @@ func TestPageTranslatorBase(t *testing.T) { t.Fatalf("Translated returned and err: %s", err) } - if dest != test.expected { + if dest != filepath.FromSlash(test.expected) { t.Errorf("Translate expected: %s, got: %s", test.expected, dest) } } @@ -73,7 +75,7 @@ func TestTranslateUglyUrls(t *testing.T) { for _, test := range tests { f := &PagePub{UglyUrls: true} - dest, err := f.Translate(test.content) + dest, err := f.Translate(filepath.FromSlash(test.content)) if err != nil { t.Fatalf("Translate returned an unexpected err: %s", err) } @@ -87,7 +89,7 @@ func TestTranslateUglyUrls(t *testing.T) { func TestTranslateDefaultExtension(t *testing.T) { f := &PagePub{DefaultExtension: ".foobar"} dest, _ := f.Translate("baz") - if dest != "baz/index.foobar" { + if dest != filepath.FromSlash("baz/index.foobar") { t.Errorf("Translate expected return: %s, got %s", "baz/index.foobar", dest) } } |