From fa71f6c11e30192316c03522bc8f2f49abe461d7 Mon Sep 17 00:00:00 2001 From: bep Date: Tue, 10 Feb 2015 19:13:45 +0100 Subject: [PATCH] Make # survice Url cleaning To enable anchors in Urls. Fixes #888 --- helpers/path.go | 2 +- hugolib/menu_test.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/helpers/path.go b/helpers/path.go index 7965a6ada..c83686062 100644 --- a/helpers/path.go +++ b/helpers/path.go @@ -92,7 +92,7 @@ func UnicodeSanitize(s string) string { target := make([]rune, 0, len(source)) for _, r := range source { - if unicode.IsLetter(r) || unicode.IsDigit(r) || r == '.' || r == '/' || r == '_' || r == '-' { + if unicode.IsLetter(r) || unicode.IsDigit(r) || r == '.' || r == '/' || r == '_' || r == '-' || r == '#' { target = append(target, r) } } diff --git a/hugolib/menu_test.go b/hugolib/menu_test.go index 6cab0a29a..75a988e7d 100644 --- a/hugolib/menu_test.go +++ b/hugolib/menu_test.go @@ -50,6 +50,10 @@ const ( name = "Tax RSS" url = "/two/key.xml" identifier="xml" +[[menu.hash]] + name = "Tax With #" + url = "/resource#anchor" + identifier="hash" [[menu.unicode]] name = "Unicode Russian" identifier = "unicode-russian" @@ -262,6 +266,18 @@ func TestPageMenu(t *testing.T) { } +// issue #888 +func TestMenuWithHashInUrl(t *testing.T) { + ts := setupMenuTests(t, MENU_PAGE_SOURCES) + defer resetMenuTestState(ts) + + me := ts.findTestMenuEntryById("hash", "hash") + + assert.NotNil(t, me) + + assert.Equal(t, "/Zoo/resource/#anchor", me.Url) +} + // issue #719 func TestMenuWithUnicodeUrls(t *testing.T) { for _, uglyUrls := range []bool{true, false} {