shithub: hugo

Download patch

ref: dbe63970e09313dec287816ab070b5c2f5a13b1b
parent: 0c90e6d710deb6a316ade0891bbf0ad83376df40
author: Bjørn Erik Pedersen <[email protected]>
date: Sat Jul 15 07:05:14 EDT 2017

hugolib: Support reflinks starting with a slash

Fixes #3703

--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -416,6 +416,9 @@
 	var refURL *url.URL
 	var err error
 
+	ref = filepath.ToSlash(ref)
+	ref = strings.TrimPrefix(ref, "/")
+
 	refURL, err = url.Parse(ref)
 
 	if err != nil {
--- a/hugolib/site_test.go
+++ b/hugolib/site_test.go
@@ -232,6 +232,8 @@
 		expectedPathSuffix = "/index.html"
 	}
 
+	doc3Slashed := filepath.FromSlash("/sect/doc3.md")
+
 	sources := []source.ByteSource{
 		{
 			Name:    filepath.FromSlash("sect/doc1.md"),
@@ -251,6 +253,11 @@
 			Name:    filepath.FromSlash("sect/doc3.md"),
 			Content: []byte(fmt.Sprintf(`**Ref 1:**{{< %s "sect/doc3.md" >}}.`, refShortcode)),
 		},
+		// Issue #3703
+		{
+			Name:    filepath.FromSlash("sect/doc4.md"),
+			Content: []byte(fmt.Sprintf(`**Ref 1:**{{< %s "%s" >}}.`, refShortcode, doc3Slashed)),
+		},
 	}
 
 	cfg, fs := newTestCfg()
@@ -271,9 +278,7 @@
 			WithTemplate: createWithTemplateFromNameValues("_default/single.html", "{{.Content}}")},
 		BuildCfg{})
 
-	if len(s.RegularPages) != 3 {
-		t.Fatalf("Expected 3 got %d pages", len(s.AllPages))
-	}
+	require.Len(t, s.RegularPages, 4)
 
 	th := testHelper{s.Cfg, s.Fs, t}
 
@@ -284,6 +289,7 @@
 		{filepath.FromSlash(fmt.Sprintf("public/sect/doc1%s", expectedPathSuffix)), fmt.Sprintf("<p>Ref 2: %s/sect/doc2%s</p>\n", expectedBase, expectedURLSuffix)},
 		{filepath.FromSlash(fmt.Sprintf("public/sect/doc2%s", expectedPathSuffix)), fmt.Sprintf("<p><strong>Ref 1:</strong></p>\n\n%s/sect/doc1%s\n\n<p>THE END.</p>\n", expectedBase, expectedURLSuffix)},
 		{filepath.FromSlash(fmt.Sprintf("public/sect/doc3%s", expectedPathSuffix)), fmt.Sprintf("<p><strong>Ref 1:</strong>%s/sect/doc3%s.</p>\n", expectedBase, expectedURLSuffix)},
+		{filepath.FromSlash(fmt.Sprintf("public/sect/doc4%s", expectedPathSuffix)), fmt.Sprintf("<p><strong>Ref 1:</strong>%s/sect/doc3%s.</p>\n", expectedBase, expectedURLSuffix)},
 	}
 
 	for _, test := range tests {