mirror of
https://github.com/gohugoio/hugo.git
synced 2025-03-23 09:43:32 +00:00
Fix unicode menu URLs
Menu urls like /categories/новости-проекта would turn into /categories/d0bdd0bed0b2d0bed181d182d0b8-d0bfd180d0bed0b5d0bad182d0b0, which is illegal, while the directory under the categories/ is created with the original name. It results in 404 not found error. This commit fixes that by make sure that SanitizeUrl() is called last. Fixes #719
This commit is contained in:
parent
e4a22255cc
commit
bb37698226
2 changed files with 32 additions and 2 deletions
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/spf13/hugo/hugofs"
|
"github.com/spf13/hugo/hugofs"
|
||||||
"github.com/spf13/hugo/source"
|
"github.com/spf13/hugo/source"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -47,7 +48,11 @@ const (
|
||||||
[[menu.tax]]
|
[[menu.tax]]
|
||||||
name = "Tax RSS"
|
name = "Tax RSS"
|
||||||
url = "/two/key.xml"
|
url = "/two/key.xml"
|
||||||
identifier="xml"`
|
identifier="xml"
|
||||||
|
[[menu.unicode]]
|
||||||
|
name = "Unicode Russian"
|
||||||
|
identifier = "unicode-russian"
|
||||||
|
url = "/новости-проекта"` // Russian => "news-project"
|
||||||
)
|
)
|
||||||
|
|
||||||
var MENU_PAGE_1 = []byte(`+++
|
var MENU_PAGE_1 = []byte(`+++
|
||||||
|
@ -139,6 +144,31 @@ func _TestPageMenu(t *testing.T) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// issue #719
|
||||||
|
func TestMenuWithUnicodeUrls(t *testing.T) {
|
||||||
|
for _, uglyUrls := range []bool{true, false} {
|
||||||
|
doTestMenuWithUnicodeUrls(t, uglyUrls)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func doTestMenuWithUnicodeUrls(t *testing.T, uglyUrls bool) {
|
||||||
|
viper.Set("UglyUrls", uglyUrls)
|
||||||
|
ts := setupMenuTests(t)
|
||||||
|
defer resetMenuTestState(ts)
|
||||||
|
|
||||||
|
unicodeRussian := ts.findTestMenuEntryById("unicode", "unicode-russian")
|
||||||
|
|
||||||
|
expectedBase := "http://foo.local/zoo/%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B8-%D0%BF%D1%80%D0%BE%D0%B5%D0%BA%D1%82%D0%B0"
|
||||||
|
var expected string
|
||||||
|
if uglyUrls {
|
||||||
|
expected = expectedBase + ".html"
|
||||||
|
} else {
|
||||||
|
expected = expectedBase + "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, expected, unicodeRussian.Url, "uglyUrls[%t]", uglyUrls)
|
||||||
|
}
|
||||||
|
|
||||||
func TestTaxonomyNodeMenu(t *testing.T) {
|
func TestTaxonomyNodeMenu(t *testing.T) {
|
||||||
ts := setupMenuTests(t)
|
ts := setupMenuTests(t)
|
||||||
defer resetMenuTestState(ts)
|
defer resetMenuTestState(ts)
|
||||||
|
|
|
@ -1168,7 +1168,7 @@ func (s *Site) permalinkStr(plink string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) prepUrl(in string) string {
|
func (s *Site) prepUrl(in string) string {
|
||||||
return helpers.Urlize(s.PrettifyUrl(in))
|
return s.PrettifyUrl(helpers.Urlize(in))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) PrettifyUrl(in string) string {
|
func (s *Site) PrettifyUrl(in string) string {
|
||||||
|
|
Loading…
Reference in a new issue