Triple-Z/Student-Management-System-Backend

未对输入数据进行校验

YouDail opened this issue · 1 comments

根据id查询学院的接口, /api/v1/departments, 未对 id 值进行校验,请求如 http://127.0.0.1:3000/api/v1/departments/-,会继续查询数据库并退出程序,fix如下:

// 对已经转换的string再尝试反转换成float64,防止输入非整数数据
_, erro := strconv.ParseFloat(id, 64)
if erro != nil  {
	result = gin.H{
		"status": "failed",
		"data":   "参数错误",
	}
	c.JSON(http.StatusBadRequest, result)
	return
}

@YouDail 感谢,有兴趣可以通过 Pull request 的方式向本仓库提交该 Fix ~