Skip to content
Myr

docs: fix SecureJSON default prefix and default-binding example output (#4861)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

The SecureJSON docs and the Context.SecureJSON comment said the default prefix is "while(1),". The engine sets secureJSONPrefix to "while(1);" (gin.go), and the example output a few lines below already shows the semicolon. The default-values binding example printed a "Colors" field that the Person struct does not have; the struct's array field is Addresses with default "foo bar", which binds to ["foo","bar"].

authored by Zain Qureshi · committed by GitHub · parent 1bd0ecf · Browse files · 2 files+3 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Diff stats

2 files+3 added−3 removed

  • other:+3 added−3 removed

2 files+3 added−3 removed

modified:docs/doc.md+2 added-2 removed
1165 unmodified lines
1166```11671168```sh1169curl -X POST http://localhost:8080/person1170{"Name":"William","Age":10,"Friends":["Will","Bill"],"Colors":["red","blue"],"LapTimes":[1,2,3]}1170{"Name":"William","Age":10,"Friends":["Will","Bill"],"Addresses":["foo","bar"],"LapTimes":[1,2,3]}1171```11721173NOTE: For default [collection values](#collection-format-for-arrays), the following rules apply:1174
586 unmodified lines
1761```17621763#### SecureJSON17641765Using SecureJSON to prevent json hijacking. Default prepends `"while(1),"` to response body if the given struct is array values.1765Using SecureJSON to prevent json hijacking. Default prepends `"while(1);"` to response body if the given struct is array values.17661767```go1768func main() {1769 r := gin.Default()
939 unmodified lines
modified:context.go+1 added-1 removed
1234 unmodified lines
1235 c.Render(code, render.IndentedJSON{Data: obj})1236}12371238// SecureJSON serializes the given struct as Secure JSON into the response body.1239// Default prepends "while(1)," to response body if the given struct is array values.1239// Default prepends "while(1);" to response body if the given struct is array values.1240// It also sets the Content-Type as "application/json".1241func (c *Context) SecureJSON(code int, obj any) {1242 c.Render(code, render.SecureJSON{Prefix: c.engine.secureJSONPrefix, Data: obj})1243}
300 unmodified lines