Repository: gohugoio/hugo (language: go)

Issue:
resources/page: Escaping colon in front matter url doesn't work with section pages
content/s1/_index.md

```text
---
title: s1
url: "/a\\:b/:slug/"
---
```

The published path does not have a colon. It is `public/ab/s1/index.html` instead of `public/a:b/s1/index.html`.

I have modified the existing integration test to include this case:

```go
// Issue 12948.
// Issue 12954.
func TestPermalinksWithEscapedColons(t *testing.T) {
	t.Parallel()

	if htesting.IsWindows() {
		t.Skip("Windows does not support colons in paths")
	}

	files := `
-- hugo.toml --
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
url: "/a\\:b/:slug/"
---
-- content/s2/p2.md --
---
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 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)
}
```


Discussion / hints:

Fix patch:
diff --git a/resources/page/page_paths.go b/resources/page/page_paths.go
index 4826ed5f9b1..ea22eab8198 100644
--- a/resources/page/page_paths.go
+++ b/resources/page/page_paths.go
@@ -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()


Test patch:
diff --git a/resources/page/permalinks_integration_test.go b/resources/page/permalinks_integration_test.go
index 4188c70ca0c..52bcd686080 100644
--- a/resources/page/permalinks_integration_test.go
+++ b/resources/page/permalinks_integration_test.go
@@ -235,6 +235,7 @@ slug: custom-recipe-2
 }
 
 // Issue 12948.
+// Issue 12954.
 func TestPermalinksWithEscapedColons(t *testing.T) {
 	t.Parallel()
 
@@ -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
@@ -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)
 }