Skip to content

Commit

Permalink
Fixed JSONP format (added semicolon) (gin-gonic#2007)
Browse files Browse the repository at this point in the history
* Fixed JSONP format (added semicolon)

* render_test fix
  • Loading branch information
gabolaev authored and ThomasObenaus committed Feb 19, 2020
1 parent 1aac61b commit b239e01
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}

Expand Down
2 changes: 1 addition & 1 deletion render/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions render/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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"))
}

Expand Down

0 comments on commit b239e01

Please sign in to comment.