Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

hotfix: allowing leading slash when call r.HTML(template_name) #2178

Merged
merged 4 commits into from
Nov 27, 2021
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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Tests
on:
push:
branches:
- master
- main
pull_request:

jobs:
Expand Down
9 changes: 9 additions & 0 deletions render/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package render

import (
"html"
"strings"

"github.com/gobuffalo/github_flavored_markdown"
"github.com/gobuffalo/plush/v4"
Expand All @@ -28,6 +29,14 @@ func HTML(names ...string) Renderer {
// in the options, then that layout file will be used
// automatically.
func (e *Engine) HTML(names ...string) Renderer {
// just allow leading slash and remove them here.
// generated actions were various by buffalo versions.
tmp := []string{}
for _, name := range names {
tmp = append(tmp, strings.TrimPrefix(name, "/"))
}
names = tmp

if e.HTMLLayout != "" && len(names) == 1 {
names = append(names, e.HTMLLayout)
}
Expand Down
19 changes: 19 additions & 0 deletions render/html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,22 @@ func Test_HTML_WithLayout_Override(t *testing.T) {
r.NoError(h.Render(bb, Data{"name": "Mark"}))
r.Equal("<html>Mark</html>", strings.TrimSpace(bb.String()))
}

func Test_HTML_LeadingSlash(t *testing.T) {
r := require.New(t)

rootFS := memfs.New()
r.NoError(rootFS.WriteFile(htmlTemplate, []byte("<%= name %>"), 0644))
r.NoError(rootFS.WriteFile(htmlLayout, []byte("<body><%= yield %></body>"), 0644))

e := NewEngine()
e.TemplatesFS = rootFS
e.HTMLLayout = htmlLayout

h := e.HTML("/my-template.html") // instead of "my-template.html"
r.Equal("text/html; charset=utf-8", h.ContentType())
bb := &bytes.Buffer{}

r.NoError(h.Render(bb, Data{"name": "Mark"}))
r.Equal("<body>Mark</body>", strings.TrimSpace(bb.String()))
}
2 changes: 1 addition & 1 deletion runtime/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package runtime

// Version is the current version of the buffalo binary
var Version = "v0.18.0"
var Version = "v0.18.1"