From: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> Date: Sun, 18 Oct 2015 08:36:27 +0000 (+0200) Subject: Preserve Unicode marks in MakePath X-Git-Tag: v0.15~101 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=36adb5fb883bb7170d062334f8aaa64ed191be68;p=brevno-suite%2Fhugo Preserve Unicode marks in MakePath Fixes #1488 --- diff --git a/helpers/path.go b/helpers/path.go index 9ead807c..018c6fec 100644 --- a/helpers/path.go +++ b/helpers/path.go @@ -96,7 +96,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 == '_' || r == '-' || r == '#' { + if unicode.IsLetter(r) || unicode.IsDigit(r) || unicode.IsMark(r) || r == '.' || r == '/' || r == '\\' || r == '_' || r == '-' || r == '#' { target = append(target, r) } } diff --git a/helpers/path_test.go b/helpers/path_test.go index 95171165..9534cf9c 100644 --- a/helpers/path_test.go +++ b/helpers/path_test.go @@ -19,22 +19,25 @@ import ( func TestMakePath(t *testing.T) { viper.Reset() defer viper.Reset() - viper.Set("RemovePathAccents", true) tests := []struct { - input string - expected string + input string + expected string + removeAccents bool }{ - {" Foo bar ", "Foo-bar"}, - {"Foo.Bar/foo_Bar-Foo", "Foo.Bar/foo_Bar-Foo"}, - {"fOO,bar:foo%bAR", "fOObarfoobAR"}, - {"FOo/BaR.html", "FOo/BaR.html"}, - {"ÑÑÑм/ÑÑÑм", "ÑÑÑм/ÑÑÑм"}, - {"ìí", "ìí"}, - {"ÐанковÑкий каÑÑиÑ", "ÐанковÑкии-каÑÑиÑ"}, + {" Foo bar ", "Foo-bar", true}, + {"Foo.Bar/foo_Bar-Foo", "Foo.Bar/foo_Bar-Foo", true}, + {"fOO,bar:foo%bAR", "fOObarfoobAR", true}, + {"FOo/BaR.html", "FOo/BaR.html", true}, + {"ÑÑÑм/ÑÑÑм", "ÑÑÑм/ÑÑÑм", true}, + {"ìí", "ìí", true}, + {"ÐанковÑкий каÑÑиÑ", "ÐанковÑкии-каÑÑиÑ", true}, + // Issue #1488 + {"सà¤à¤¸à¥à¤à¥à¤¤", "सà¤à¤¸à¥à¤à¥à¤¤", false}, } for _, test := range tests { + viper.Set("RemovePathAccents", test.removeAccents) output := MakePath(test.input) if output != test.expected { t.Errorf("Expected %#v, got %#v\n", test.expected, output)