Skip to content

Commit dbe6397

Browse files
committed
hugolib: Support reflinks starting with a slash
Fixes #3703
1 parent 0c90e6d commit dbe6397

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

‎hugolib/site.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,9 @@ func (s *SiteInfo) refLink(ref string, page *Page, relative bool, outputFormat s
416416
var refURL *url.URL
417417
var err error
418418

419+
ref = filepath.ToSlash(ref)
420+
ref = strings.TrimPrefix(ref, "/")
421+
419422
refURL, err = url.Parse(ref)
420423

421424
if err != nil {

‎hugolib/site_test.go‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ func doTestCrossrefs(t *testing.T, relative, uglyURLs bool) {
232232
expectedPathSuffix = "/index.html"
233233
}
234234

235+
doc3Slashed := filepath.FromSlash("/sect/doc3.md")
236+
235237
sources := []source.ByteSource{
236238
{
237239
Name: filepath.FromSlash("sect/doc1.md"),
@@ -251,6 +253,11 @@ THE END.`, refShortcode)),
251253
Name: filepath.FromSlash("sect/doc3.md"),
252254
Content: []byte(fmt.Sprintf(`**Ref 1:**{{< %s "sect/doc3.md" >}}.`, refShortcode)),
253255
},
256+
// Issue #3703
257+
{
258+
Name: filepath.FromSlash("sect/doc4.md"),
259+
Content: []byte(fmt.Sprintf(`**Ref 1:**{{< %s "%s" >}}.`, refShortcode, doc3Slashed)),
260+
},
254261
}
255262

256263
cfg, fs := newTestCfg()
@@ -271,9 +278,7 @@ THE END.`, refShortcode)),
271278
WithTemplate: createWithTemplateFromNameValues("_default/single.html", "{{.Content}}")},
272279
BuildCfg{})
273280

274-
if len(s.RegularPages) != 3 {
275-
t.Fatalf("Expected 3 got %d pages", len(s.AllPages))
276-
}
281+
require.Len(t, s.RegularPages, 4)
277282

278283
th := testHelper{s.Cfg, s.Fs, t}
279284

@@ -284,6 +289,7 @@ THE END.`, refShortcode)),
284289
{filepath.FromSlash(fmt.Sprintf("public/sect/doc1%s", expectedPathSuffix)), fmt.Sprintf("<p>Ref 2: %s/sect/doc2%s</p>\n", expectedBase, expectedURLSuffix)},
285290
{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)},
286291
{filepath.FromSlash(fmt.Sprintf("public/sect/doc3%s", expectedPathSuffix)), fmt.Sprintf("<p><strong>Ref 1:</strong>%s/sect/doc3%s.</p>\n", expectedBase, expectedURLSuffix)},
292+
{filepath.FromSlash(fmt.Sprintf("public/sect/doc4%s", expectedPathSuffix)), fmt.Sprintf("<p><strong>Ref 1:</strong>%s/sect/doc3%s.</p>\n", expectedBase, expectedURLSuffix)},
287293
}
288294

289295
for _, test := range tests {

0 commit comments

Comments
 (0)