diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-03-16 10:04:30 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-03-27 15:43:56 +0200 |
commit | a49bf8707b7f247f1c83b8087abd02a84d2ba136 (patch) | |
tree | 7a8be1f41507ee103771ab8ec2c03f7a460097fe /hugolib/alias_test.go | |
parent | d76e5f36b412eb68be3cd5a53bacc099ec46280f (diff) | |
download | hugo-a49bf8707b7f247f1c83b8087abd02a84d2ba136.tar.gz hugo-a49bf8707b7f247f1c83b8087abd02a84d2ba136.zip |
hugolib: Remove siteWriter
Diffstat (limited to 'hugolib/alias_test.go')
-rw-r--r-- | hugolib/alias_test.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/hugolib/alias_test.go b/hugolib/alias_test.go index cd8ef3496..f5e6d8d1f 100644 --- a/hugolib/alias_test.go +++ b/hugolib/alias_test.go @@ -15,6 +15,7 @@ package hugolib import ( "path/filepath" + "runtime" "testing" "github.com/spf13/hugo/deps" @@ -73,3 +74,45 @@ func TestAliasTemplate(t *testing.T) { // the alias redirector th.assertFileContent(filepath.Join("public", "foo", "bar", "index.html"), "ALIASTEMPLATE") } + +func TestTargetPathHTMLRedirectAlias(t *testing.T) { + h := newAliasHandler(nil, newErrorLogger(), false) + + errIsNilForThisOS := runtime.GOOS != "windows" + + tests := []struct { + value string + expected string + errIsNil bool + }{ + {"", "", false}, + {"s", filepath.FromSlash("s/index.html"), true}, + {"/", "", false}, + {"alias 1", filepath.FromSlash("alias 1/index.html"), true}, + {"alias 2/", filepath.FromSlash("alias 2/index.html"), true}, + {"alias 3.html", "alias 3.html", true}, + {"alias4.html", "alias4.html", true}, + {"/alias 5.html", "alias 5.html", true}, + {"/трям.html", "трям.html", true}, + {"../../../../tmp/passwd", "", false}, + {"/foo/../../../../tmp/passwd", filepath.FromSlash("tmp/passwd/index.html"), true}, + {"foo/../../../../tmp/passwd", "", false}, + {"C:\\Windows", filepath.FromSlash("C:\\Windows/index.html"), errIsNilForThisOS}, + {"/trailing-space /", filepath.FromSlash("trailing-space /index.html"), errIsNilForThisOS}, + {"/trailing-period./", filepath.FromSlash("trailing-period./index.html"), errIsNilForThisOS}, + {"/tab\tseparated/", filepath.FromSlash("tab\tseparated/index.html"), errIsNilForThisOS}, + {"/chrome/?p=help&ctx=keyboard#topic=3227046", filepath.FromSlash("chrome/?p=help&ctx=keyboard#topic=3227046/index.html"), errIsNilForThisOS}, + {"/LPT1/Printer/", filepath.FromSlash("LPT1/Printer/index.html"), errIsNilForThisOS}, + } + + for _, test := range tests { + path, err := h.targetPathAlias(test.value) + if (err == nil) != test.errIsNil { + t.Errorf("Expected err == nil => %t, got: %t. err: %s", test.errIsNil, err == nil, err) + continue + } + if err == nil && path != test.expected { + t.Errorf("Expected: \"%s\", got: \"%s\"", test.expected, path) + } + } +} |