Skip to content

Commit 5be0448

Browse files
committed
hugolib: Fix disablePathToLower regression
Fixes #3374
1 parent 1f55cb7 commit 5be0448

File tree

2 files changed

+65
-45
lines changed

2 files changed

+65
-45
lines changed

‎hugolib/page_paths.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (p *Page) initTargetPathDescriptor() error {
8585
Kind: p.Kind,
8686
Sections: p.sections,
8787
UglyURLs: p.s.Info.uglyURLs,
88-
Dir: filepath.ToSlash(strings.ToLower(p.Source.Dir())),
88+
Dir: filepath.ToSlash(p.Source.Dir()),
8989
URL: p.URLPath.URL,
9090
}
9191

‎hugolib/page_test.go‎

Lines changed: 64 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,70 +1417,90 @@ func TestShouldBuild(t *testing.T) {
14171417
}
14181418
}
14191419

1420-
// Issue #1885 and #2110
1421-
func TestDotInPath(t *testing.T) {
1420+
// "dot" in path: #1885 and #2110
1421+
// disablePathToLower regression: #3374
1422+
func TestPathIssues(t *testing.T) {
14221423
t.Parallel()
1424+
for _, disablePathToLower := range []bool{false, true} {
1425+
for _, uglyURLs := range []bool{false, true} {
1426+
t.Run(fmt.Sprintf("disablePathToLower=%t,uglyURLs=%t", disablePathToLower, uglyURLs), func(t *testing.T) {
14231427

1424-
for _, uglyURLs := range []bool{false, true} {
1425-
t.Run(fmt.Sprintf("uglyURLs=%t", uglyURLs), func(t *testing.T) {
1428+
cfg, fs := newTestCfg()
1429+
th := testHelper{cfg, fs, t}
14261430

1427-
cfg, fs := newTestCfg()
1428-
th := testHelper{cfg, fs, t}
1431+
cfg.Set("permalinks", map[string]string{
1432+
"post": ":section/:title",
1433+
})
14291434

1430-
cfg.Set("permalinks", map[string]string{
1431-
"post": ":section/:title",
1432-
})
1433-
1434-
cfg.Set("uglyURLs", uglyURLs)
1435-
cfg.Set("paginate", 1)
1435+
cfg.Set("uglyURLs", uglyURLs)
1436+
cfg.Set("disablePathToLower", disablePathToLower)
1437+
cfg.Set("paginate", 1)
14361438

1437-
writeSource(t, fs, filepath.Join("layouts", "_default", "single.html"), "<html><body>{{.Content}}</body></html>")
1438-
writeSource(t, fs, filepath.Join("layouts", "_default", "list.html"),
1439-
"<html><body>P{{.Paginator.PageNumber}}|URL: {{.Paginator.URL}}|{{ if .Paginator.HasNext }}Next: {{.Paginator.Next.URL }}{{ end }}</body></html>")
1439+
writeSource(t, fs, filepath.Join("layouts", "_default", "single.html"), "<html><body>{{.Content}}</body></html>")
1440+
writeSource(t, fs, filepath.Join("layouts", "_default", "list.html"),
1441+
"<html><body>P{{.Paginator.PageNumber}}|URL: {{.Paginator.URL}}|{{ if .Paginator.HasNext }}Next: {{.Paginator.Next.URL }}{{ end }}</body></html>")
14401442

1441-
for i := 0; i < 3; i++ {
1442-
writeSource(t, fs, filepath.Join("content", "post", fmt.Sprintf("doc%d.md", i)),
1443-
fmt.Sprintf(`---
1443+
for i := 0; i < 3; i++ {
1444+
writeSource(t, fs, filepath.Join("content", "post", fmt.Sprintf("doc%d.md", i)),
1445+
fmt.Sprintf(`---
14441446
title: "test%d.dot"
14451447
tags:
14461448
- ".net"
14471449
---
14481450
# doc1
14491451
*some content*`, i))
1450-
}
1452+
}
1453+
1454+
writeSource(t, fs, filepath.Join("content", "Blog", "Blog1.md"),
1455+
fmt.Sprintf(`---
1456+
title: "testBlog"
1457+
tags:
1458+
- "Blog"
1459+
---
1460+
# doc1
1461+
*some blog content*`))
14511462

1452-
s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
1453-
require.Len(t, s.RegularPages, 3)
1463+
s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
1464+
require.Len(t, s.RegularPages, 4)
14541465

1455-
pathFunc := func(s string) string {
1456-
if uglyURLs {
1457-
return strings.Replace(s, "/index.html", ".html", 1)
1466+
pathFunc := func(s string) string {
1467+
if uglyURLs {
1468+
return strings.Replace(s, "/index.html", ".html", 1)
1469+
}
1470+
return s
14581471
}
1459-
return s
1460-
}
14611472

1462-
th.assertFileContent(pathFunc("public/post/test0.dot/index.html"), "some content")
1473+
blog := "blog"
14631474

1464-
if uglyURLs {
1465-
th.assertFileContent("public/post/page/1.html", `canonical" href="/post.html"/`)
1466-
th.assertFileContent("public/post.html", `<body>P1|URL: /post.html|Next: /post/page/2.html</body>`)
1467-
th.assertFileContent("public/post/page/2.html", `<body>P2|URL: /post/page/2.html|Next: /post/page/3.html</body>`)
1468-
} else {
1469-
th.assertFileContent("public/post/page/1/index.html", `canonical" href="/post/"/`)
1470-
th.assertFileContent("public/post/index.html", `<body>P1|URL: /post/|Next: /post/page/2/</body>`)
1471-
th.assertFileContent("public/post/page/2/index.html", `<body>P2|URL: /post/page/2/|Next: /post/page/3/</body>`)
1472-
th.assertFileContent("public/tags/.net/index.html", `<body>P1|URL: /tags/.net/|Next: /tags/.net/page/2/</body>`)
1475+
if disablePathToLower {
1476+
blog = "Blog"
1477+
}
14731478

1474-
}
1479+
th.assertFileContent(pathFunc("public/"+blog+"/"+blog+"1/index.html"), "some blog content")
14751480

1476-
p := s.RegularPages[0]
1477-
if uglyURLs {
1478-
require.Equal(t, "/post/test0.dot.html", p.RelPermalink())
1479-
} else {
1480-
require.Equal(t, "/post/test0.dot/", p.RelPermalink())
1481-
}
1481+
th.assertFileContent(pathFunc("public/post/test0.dot/index.html"), "some content")
1482+
1483+
if uglyURLs {
1484+
th.assertFileContent("public/post/page/1.html", `canonical" href="/post.html"/`)
1485+
th.assertFileContent("public/post.html", `<body>P1|URL: /post.html|Next: /post/page/2.html</body>`)
1486+
th.assertFileContent("public/post/page/2.html", `<body>P2|URL: /post/page/2.html|Next: /post/page/3.html</body>`)
1487+
} else {
1488+
th.assertFileContent("public/post/page/1/index.html", `canonical" href="/post/"/`)
1489+
th.assertFileContent("public/post/index.html", `<body>P1|URL: /post/|Next: /post/page/2/</body>`)
1490+
th.assertFileContent("public/post/page/2/index.html", `<body>P2|URL: /post/page/2/|Next: /post/page/3/</body>`)
1491+
th.assertFileContent("public/tags/.net/index.html", `<body>P1|URL: /tags/.net/|Next: /tags/.net/page/2/</body>`)
1492+
1493+
}
1494+
1495+
p := s.RegularPages[0]
1496+
if uglyURLs {
1497+
require.Equal(t, "/post/test0.dot.html", p.RelPermalink())
1498+
} else {
1499+
require.Equal(t, "/post/test0.dot/", p.RelPermalink())
1500+
}
14821501

1483-
})
1502+
})
1503+
}
14841504
}
14851505
}
14861506

0 commit comments

Comments
 (0)