Skip to content

Commit

Permalink
helpers: fix invalid pagination links
Browse files Browse the repository at this point in the history
The path helper incorrectly transforms valid urls causing issues with
pagination. One example is `.net`

http://localhost:1313/tags/.net/
to
http://localhost:1313/tags/index.net/page/2

The commit adds a regex test to check for `.xml` or `.html` extensions
and applies the transformation on a match.

This allows valid URLs like /foo/index.html/bar to also be passed
through.

Fixes gohugoio#2110
  • Loading branch information
shapeshed committed Oct 3, 2016
1 parent f914774 commit f772902
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 10 additions & 1 deletion helpers/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,17 @@ func prettifyPath(in string, b filepathPathBridge) string {
// /section/name/index.html -> /section/name/index.html
return b.Clean(in)
}

// /section/name.html -> /section/name/index.html
return b.Join(b.Dir(in), name, "index"+ext)
// /.xml -> /index.xml
// /node.js/page/2 -> /node.js/page/2
r := regexp.MustCompile("[.html|.xml]$")
if r.MatchString(ext) {
return b.Join(b.Dir(in), name, "index"+ext)
} else {
return b.Clean(in)
}

}

// ExtractRootPaths extracts the root paths from the supplied list of paths.
Expand Down
2 changes: 2 additions & 0 deletions helpers/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ func TestPretty(t *testing.T) {
assert.Equal(t, PrettifyURL("/section/name/index.html"), "/section/name")
assert.Equal(t, PrettifyURL("/index.html"), "/")
assert.Equal(t, PrettifyURL("/name.xml"), "/name/index.xml")
assert.Equal(t, PrettifyURL("/node.js/page/2"), "/node.js/page/2")
assert.Equal(t, PrettifyURL("/index.html/page/2"), "/index.html/page/2")
assert.Equal(t, PrettifyURL("/"), "/")
assert.Equal(t, PrettifyURL(""), "/")
}
Expand Down

0 comments on commit f772902

Please sign in to comment.