summaryrefslogtreecommitdiffstats
path: root/resources
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-01-17 11:00:38 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-01-17 12:49:16 +0100
commit671f64b2eba077e2456a32feabfa94e5dc8af511 (patch)
treebb1116fe1f45f07b1739b6237f62738ba0cbf137 /resources
parent2fb40ece5df38c3d6565cfd69ae194dbe0126f53 (diff)
Fix permalinks issue with repeated sections
Fixes #10377
Diffstat (limited to 'resources')
-rw-r--r--resources/page/integration_test.go39
-rw-r--r--resources/page/permalinks.go2
-rw-r--r--resources/page/permalinks_test.go1
3 files changed, 41 insertions, 1 deletions
diff --git a/resources/page/integration_test.go b/resources/page/integration_test.go
index 9dc322b4a..0761de249 100644
--- a/resources/page/integration_test.go
+++ b/resources/page/integration_test.go
@@ -136,3 +136,42 @@ Sort: [éclair emma xylophone zulu]
ByWeight: alpha|émotion|zulu|
`)
}
+
+// See #10377
+func TestPermalinkExpansionSectionsRepeated(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+disableKinds = ["home", "taxonomy", "taxonomyTerm", "sitemap"]
+[outputs]
+home = ["HTML"]
+page = ["HTML"]
+section = ["HTML"]
+[outputFormats]
+[permalinks]
+posts = '/:sections[1]/:sections[last]/:slug'
+-- content/posts/_index.md --
+-- content/posts/a/_index.md --
+-- content/posts/a/b/_index.md --
+-- content/posts/a/b/c/_index.md --
+-- content/posts/a/b/c/d.md --
+---
+title: "D"
+slug: "d"
+---
+D
+-- layouts/_default/single.html --
+RelPermalink: {{ .RelPermalink }}
+
+`
+
+ b := hugolib.NewIntegrationTestBuilder(
+ hugolib.IntegrationTestConfig{
+ T: t,
+ TxtarString: files,
+ }).Build()
+
+ b.AssertFileContent("public/a/c/d/index.html", "RelPermalink: /a/c/d/")
+
+}
diff --git a/resources/page/permalinks.go b/resources/page/permalinks.go
index c31d22a3c..dbf10220c 100644
--- a/resources/page/permalinks.go
+++ b/resources/page/permalinks.go
@@ -176,7 +176,7 @@ func (l PermalinkExpander) parse(patterns map[string]string) (map[string]func(Pa
// can return a string to go in that position in the page (or an error)
type pageToPermaAttribute func(Page, string) (string, error)
-var attributeRegexp = regexp.MustCompile(`:\w+(\[.+\])?`)
+var attributeRegexp = regexp.MustCompile(`:\w+(\[.+?\])?`)
// validate determines if a PathPattern is well-formed
func (l PermalinkExpander) validate(pp string) bool {
diff --git a/resources/page/permalinks_test.go b/resources/page/permalinks_test.go
index 7baf16503..07333492f 100644
--- a/resources/page/permalinks_test.go
+++ b/resources/page/permalinks_test.go
@@ -42,6 +42,7 @@ var testdataPermalinks = []struct {
{"/:2006_01_02_15_04_05.000", true, "/2012_04_06_03_01_59.000"}, // Complicated custom date format
{"/:sections/", true, "/a/b/c/"}, // Sections
{"/:sections[last]/", true, "/c/"}, // Sections
+ {"/:sections[0]/:sections[last]/", true, "/a/c/"}, // Sections
// Failures
{"/blog/:fred", false, ""},