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

Add utf8 to content type for html #1314

Merged
merged 2 commits into from
Sep 20, 2018
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 errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func productionErrorResponseFor(status int) []byte {

func defaultErrorHandler(status int, origErr error, c Context) error {
env := c.Value("env")
ct := defaults.String(httpx.ContentType(c.Request()), "text/html")
ct := defaults.String(httpx.ContentType(c.Request()), "text/html; charset=utf-8")
c.Response().Header().Set("content-type", ct)

c.Logger().Error(origErr)
Expand Down
2 changes: 1 addition & 1 deletion errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func Test_defaultErrorHandler_SetsContentType(t *testing.T) {
res := w.HTML("/").Get()
r.Equal(401, res.Code)
ct := res.Header().Get("content-type")
r.Equal("text/html", ct)
r.Equal("text/html; charset=utf-8", ct)
}

func Test_PanicHandler(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion render/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (e *Engine) HTML(names ...string) Renderer {
}
hr := &templateRenderer{
Engine: e,
contentType: "text/html",
contentType: "text/html; charset=utf-8",
names: names,
}
return hr
Expand Down
6 changes: 3 additions & 3 deletions render/html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func Test_HTML(t *testing.T) {
}).HTML

re := j(filepath.Base(tmpFile.Name()))
r.Equal("text/html", re.ContentType())
r.Equal("text/html; charset=utf-8", re.ContentType())
bb := &bytes.Buffer{}
err = re.Render(bb, map[string]interface{}{"name": "Mark"})
r.NoError(err)
Expand All @@ -61,7 +61,7 @@ func Test_HTML(t *testing.T) {
r := require.New(sst)
h := re.HTML(filepath.Base(tmpFile.Name()))

r.Equal("text/html", h.ContentType())
r.Equal("text/html; charset=utf-8", h.ContentType())
bb := &bytes.Buffer{}
err = h.Render(bb, map[string]interface{}{"name": "Mark"})
r.NoError(err)
Expand All @@ -78,7 +78,7 @@ func Test_HTML(t *testing.T) {
r.NoError(err)
h := re.HTML(filepath.Base(tmpFile.Name()), filepath.Base(nlayout.Name()))

r.Equal("text/html", h.ContentType())
r.Equal("text/html; charset=utf-8", h.ContentType())
bb := &bytes.Buffer{}
err = h.Render(bb, map[string]interface{}{"name": "Mark"})
r.NoError(err)
Expand Down
4 changes: 2 additions & 2 deletions render/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func Test_Markdown(t *testing.T) {

for _, j := range table {
re := j(filepath.Base(tmpFile.Name()))
r.Equal("text/html", re.ContentType())
r.Equal("text/html; charset=utf-8", re.ContentType())
bb := &bytes.Buffer{}
err = re.Render(bb, map[string]interface{}{"name": "Mark"})
r.NoError(err)
Expand All @@ -61,7 +61,7 @@ func Test_Markdown(t *testing.T) {
TemplatesBox: packr.NewBox(tmpDir),
}).HTML(filepath.Base(tmpFile.Name()))

r.Equal("text/html", re.ContentType())
r.Equal("text/html; charset=utf-8", re.ContentType())
bb := &bytes.Buffer{}
err = re.Render(bb, map[string]interface{}{"name": "Mark"})
r.NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion render/partials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func Test_Template_Partial_WithoutExtension(t *testing.T) {
err := withHTMLFile("index.html", `<%= partial("foo") %>`, func(e *Engine) {
err := withHTMLFile("_foo.html", "Foo > <%= name %>", func(e *Engine) {

re := e.Template("text/html", "index.html")
re := e.Template("text/html; charset=utf-8", "index.html")
bb := &bytes.Buffer{}
err := re.Render(bb, Data{"name": "Mark"})
r.NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func New(opts Options) *Engine {
}

if opts.DefaultContentType == "" {
opts.DefaultContentType = "text/html"
opts.DefaultContentType = "text/html; charset=utf-8"
}

e := &Engine{
Expand Down
6 changes: 3 additions & 3 deletions render/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func Test_AssetPath(t *testing.T) {
_, err = tmpFile.Write([]byte("<%= assetPath(\"" + original + "\") %>"))
r.NoError(err)

result := re("text/html", filepath.Base(tmpFile.Name()))
result := re("text/html; charset=utf-8", filepath.Base(tmpFile.Name()))

bb := &bytes.Buffer{}
err = result.Render(bb, render.Data{})
Expand Down Expand Up @@ -123,7 +123,7 @@ func Test_AssetPathNoManifest(t *testing.T) {
_, err = tmpFile.Write([]byte("<%= assetPath(\"" + original + "\") %>"))
r.NoError(err)

result := re("text/html", filepath.Base(tmpFile.Name()))
result := re("text/html; charset=utf-8", filepath.Base(tmpFile.Name()))

bb := &bytes.Buffer{}
err = result.Render(bb, render.Data{})
Expand Down Expand Up @@ -166,7 +166,7 @@ func Test_AssetPathManifestCorrupt(t *testing.T) {
_, err = tmpFile.Write([]byte("<%= assetPath(\"" + original + "\") %>"))
r.NoError(err)

result := re("text/html", filepath.Base(tmpFile.Name()))
result := re("text/html; charset=utf-8", filepath.Base(tmpFile.Name()))

bb := &bytes.Buffer{}
err = result.Render(bb, render.Data{})
Expand Down