From 01ca625b98910363175cd24b0093c6f14e9d6dd3 Mon Sep 17 00:00:00 2001 From: George Gabolaev Date: Mon, 2 Sep 2019 15:18:08 +0300 Subject: [PATCH] Fixed JSONP format (added semicolon) (#2007) * Fixed JSONP format (added semicolon) * render_test fix --- context_test.go | 2 +- render/json.go | 2 +- render/render_test.go | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/context_test.go b/context_test.go index 439e8ee6..f7bb0f51 100644 --- a/context_test.go +++ b/context_test.go @@ -676,7 +676,7 @@ func TestContextRenderJSONP(t *testing.T) { c.JSONP(http.StatusCreated, H{"foo": "bar"}) assert.Equal(t, http.StatusCreated, w.Code) - assert.Equal(t, "x({\"foo\":\"bar\"})", w.Body.String()) + assert.Equal(t, "x({\"foo\":\"bar\"});", w.Body.String()) assert.Equal(t, "application/javascript; charset=utf-8", w.Header().Get("Content-Type")) } diff --git a/render/json.go b/render/json.go index 2b07cba0..70506f78 100644 --- a/render/json.go +++ b/render/json.go @@ -138,7 +138,7 @@ func (r JsonpJSON) Render(w http.ResponseWriter) (err error) { if err != nil { return err } - _, err = w.Write([]byte(")")) + _, err = w.Write([]byte(");")) if err != nil { return err } diff --git a/render/render_test.go b/render/render_test.go index 4cc71972..b27134ff 100644 --- a/render/render_test.go +++ b/render/render_test.go @@ -146,7 +146,7 @@ func TestRenderJsonpJSON(t *testing.T) { err1 := (JsonpJSON{"x", data}).Render(w1) assert.NoError(t, err1) - assert.Equal(t, "x({\"foo\":\"bar\"})", w1.Body.String()) + assert.Equal(t, "x({\"foo\":\"bar\"});", w1.Body.String()) assert.Equal(t, "application/javascript; charset=utf-8", w1.Header().Get("Content-Type")) w2 := httptest.NewRecorder() @@ -158,7 +158,7 @@ func TestRenderJsonpJSON(t *testing.T) { err2 := (JsonpJSON{"x", datas}).Render(w2) assert.NoError(t, err2) - assert.Equal(t, "x([{\"foo\":\"bar\"},{\"bar\":\"foo\"}])", w2.Body.String()) + assert.Equal(t, "x([{\"foo\":\"bar\"},{\"bar\":\"foo\"}]);", w2.Body.String()) assert.Equal(t, "application/javascript; charset=utf-8", w2.Header().Get("Content-Type")) }