Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resources: Preserve url set in frontmatter without sanitizing #7974

Merged
merged 1 commit into from
Nov 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions resources/page/page_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,16 @@ func CreateTargetPaths(d TargetPathDescriptor) (tp TargetPaths) {

linkDir = strings.TrimSuffix(path.Join(slash, linkDir), slash)

// Note: MakePathSanitized will lower case the path if
// disablePathToLower isn't set.
pagePath = d.PathSpec.MakePathSanitized(pagePath)
pagePathDir = d.PathSpec.MakePathSanitized(pagePathDir)
link = d.PathSpec.MakePathSanitized(link)
linkDir = d.PathSpec.MakePathSanitized(linkDir)
// if page URL is explicitly set in frontmatter,
// preserve its value without sanitization
if d.Kind != KindPage || d.URL == "" {
// Note: MakePathSanitized will lower case the path if
// disablePathToLower isn't set.
pagePath = d.PathSpec.MakePathSanitized(pagePath)
pagePathDir = d.PathSpec.MakePathSanitized(pagePathDir)
link = d.PathSpec.MakePathSanitized(link)
linkDir = d.PathSpec.MakePathSanitized(linkDir)
}

tp.TargetFilename = filepath.FromSlash(pagePath)
tp.SubResourceBaseTarget = filepath.FromSlash(pagePathDir)
Expand Down
7 changes: 7 additions & 0 deletions resources/page/page_paths_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ func TestPageTargetPath(t *testing.T) {
BaseName: "mypage",
URL: "/some/other/path",
Type: output.HTMLFormat}, TargetPaths{TargetFilename: "/some/other/path/index.html", SubResourceBaseTarget: "/some/other/path", Link: "/some/other/path/"}},
{
"HTML page with URL containing double hyphen", TargetPathDescriptor{
Kind: KindPage,
Dir: "/sect/",
BaseName: "mypage",
URL: "/some/other--url/",
Type: output.HTMLFormat}, TargetPaths{TargetFilename: "/some/other--url/index.html", SubResourceBaseTarget: "/some/other--url", Link: "/some/other--url/"}},
{
"HTML page with expanded permalink", TargetPathDescriptor{
Kind: KindPage,
Expand Down