mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-16 13:22:09 +08:00
added typechecking function
This commit is contained in:
parent
eac2daac64
commit
961513d2c1
10
context.go
10
context.go
@ -962,6 +962,16 @@ func (c *Context) JSONP(code int, obj any) {
|
|||||||
c.Render(code, render.JSON{Data: obj})
|
c.Render(code, render.JSON{Data: obj})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add type checking for the callback function name
|
||||||
|
callbackPattern := `^[\p{L}\p{N}_]+$` // Unicode-aware pattern for alphanumeric characters and underscores
|
||||||
|
isValidCallback := regexp.MustCompile(callbackPattern).MatchString(callback)
|
||||||
|
if !isValidCallback {
|
||||||
|
// Handle the invalid callback function name, e.g., return an error or set a default callback function name
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid callback function name"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
c.Render(code, render.JsonpJSON{Callback: callback, Data: obj})
|
c.Render(code, render.JsonpJSON{Callback: callback, Data: obj})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user