Remove transformation of menu URLs

Fixes #1239
This commit is contained in:
gunnaraasen 2015-12-02 14:58:54 -08:00 committed by Bjørn Erik Pedersen
parent f6fdfcd429
commit d35d82060f
2 changed files with 12 additions and 19 deletions

View file

@ -47,7 +47,7 @@ const (
identifier="1" identifier="1"
[[menu.tax]] [[menu.tax]]
name = "Tax2" name = "Tax2"
url = "/two/key" url = "/two/key/"
identifier="2" identifier="2"
[[menu.tax]] [[menu.tax]]
name = "Tax RSS" name = "Tax RSS"
@ -304,44 +304,34 @@ func TestMenuWithHashInURL(t *testing.T) {
assert.NotNil(t, me) assert.NotNil(t, me)
assert.Equal(t, "/Zoo/resource/#anchor", me.URL) assert.Equal(t, "/Zoo/resource#anchor", me.URL)
} }
// issue #719 // issue #719
func TestMenuWithUnicodeURLs(t *testing.T) { func TestMenuWithUnicodeURLs(t *testing.T) {
for _, uglyURLs := range []bool{true, false} {
for _, canonifyURLs := range []bool{true, false} { for _, canonifyURLs := range []bool{true, false} {
doTestMenuWithUnicodeURLs(t, canonifyURLs, uglyURLs) doTestMenuWithUnicodeURLs(t, canonifyURLs)
}
} }
} }
func doTestMenuWithUnicodeURLs(t *testing.T, canonifyURLs, uglyURLs bool) { func doTestMenuWithUnicodeURLs(t *testing.T, canonifyURLs bool) {
viper.Reset() viper.Reset()
defer viper.Reset() defer viper.Reset()
viper.Set("CanonifyURLs", canonifyURLs) viper.Set("CanonifyURLs", canonifyURLs)
viper.Set("UglyURLs", uglyURLs)
s := setupMenuTests(t, MENU_PAGE_SOURCES) s := setupMenuTests(t, MENU_PAGE_SOURCES)
unicodeRussian := findTestMenuEntryByID(s, "unicode", "unicode-russian") unicodeRussian := findTestMenuEntryByID(s, "unicode", "unicode-russian")
expectedBase := "/%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" expected := "/%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"
if !canonifyURLs { if !canonifyURLs {
expectedBase = "/Zoo" + expectedBase expected = "/Zoo" + expected
} }
var expected string assert.Equal(t, expected, unicodeRussian.URL)
if uglyURLs {
expected = expectedBase + ".html"
} else {
expected = expectedBase + "/"
}
assert.Equal(t, expected, unicodeRussian.URL, "uglyURLs[%t]", uglyURLs)
} }
// Issue #1114 // Issue #1114
@ -383,6 +373,9 @@ func doTestSectionPagesMenu(canonifyUrls bool, t *testing.T) {
assert.NotNil(t, fishySectionMenuEntry) assert.NotNil(t, fishySectionMenuEntry)
assert.NotNil(t, nodeFishy) assert.NotNil(t, nodeFishy)
firstSectionMenuEntry.URL = firstSectionMenuEntry.URL + "/"
secondSectionMenuEntry.URL = secondSectionMenuEntry.URL + "/"
fishySectionMenuEntry.URL = fishySectionMenuEntry.URL + "/"
assert.True(t, nodeFirst.IsMenuCurrent("spm", firstSectionMenuEntry)) assert.True(t, nodeFirst.IsMenuCurrent("spm", firstSectionMenuEntry))
assert.False(t, nodeFirst.IsMenuCurrent("spm", secondSectionMenuEntry)) assert.False(t, nodeFirst.IsMenuCurrent("spm", secondSectionMenuEntry))
assert.False(t, nodeFirst.IsMenuCurrent("spm", fishySectionMenuEntry)) assert.False(t, nodeFirst.IsMenuCurrent("spm", fishySectionMenuEntry))

View file

@ -736,7 +736,7 @@ func (s *SiteInfo) createNodeMenuEntryURL(in string) string {
} }
// make it match the nodes // make it match the nodes
menuEntryURL := in menuEntryURL := in
menuEntryURL = helpers.URLizeAndPrep(menuEntryURL) menuEntryURL = helpers.SanitizeURLKeepTrailingSlash(helpers.URLize(menuEntryURL))
if !s.canonifyURLs { if !s.canonifyURLs {
menuEntryURL = helpers.AddContextRoot(string(s.BaseURL), menuEntryURL) menuEntryURL = helpers.AddContextRoot(string(s.BaseURL), menuEntryURL)
} }