Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Never sanitize when set in front matter #12955

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resources/page/page_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func CreateTargetPaths(d TargetPathDescriptor) (tp TargetPaths) {

// if page URL is explicitly set in frontmatter,
// preserve its value without sanitization
if d.Kind != kinds.KindPage || d.URL == "" {
if d.URL == "" {
// Note: MakePathSanitized will lower case the path if
// disablePathToLower isn't set.
pb.Sanitize()
Expand Down
13 changes: 11 additions & 2 deletions resources/page/permalinks_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ slug: custom-recipe-2
}

// Issue 12948.
// Issue 12954.
func TestPermalinksWithEscapedColons(t *testing.T) {
t.Parallel()

Expand All @@ -244,9 +245,14 @@ func TestPermalinksWithEscapedColons(t *testing.T) {

files := `
-- hugo.toml --
disableKinds = ['home','rss','section','sitemap','taxonomy','term']
disableKinds = ['home','rss','sitemap','taxonomy','term']
[permalinks.page]
s2 = "/c\\:d/:slug/"
-- content/s1/_index.md --
---
title: s1
url: "/a\\:b/:slug/"
---
-- content/s1/p1.md --
---
title: p1
Expand All @@ -258,13 +264,16 @@ title: p2
---
-- layouts/_default/single.html --
{{ .Title }}
-- layouts/_default/list.html --
{{ .Title }}
`

b := hugolib.Test(t, files)

b.AssertFileExists("public/a:b/p1/index.html", true)
b.AssertFileExists("public/a:b/s1/index.html", true)

// The above URL comes from the URL front matter field where everything is allowed.
// The above URLs come from the URL front matter field where everything is allowed.
// We strip colons from paths constructed by Hugo (they are not supported on Windows).
b.AssertFileExists("public/cd/p2/index.html", true)
}