validate model tags on copy (#1323)

This commit is contained in:
Bruce MacDonald
2023-11-29 15:54:29 -05:00
committed by GitHub
parent 39be7fdb98
commit 96122b7271
2 changed files with 21 additions and 2 deletions

View File

@@ -416,8 +416,8 @@ func CreateModelHandler(c *gin.Context) {
return
}
if strings.Count(req.Name, ":") > 1 {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "':' (colon) is not allowed in tag names"})
if err := ParseModelPath(req.Name).Validate(); err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
@@ -645,6 +645,11 @@ func CopyModelHandler(c *gin.Context) {
return
}
if err := ParseModelPath(req.Destination).Validate(); err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
if err := CopyModel(req.Source, req.Destination); err != nil {
if os.IsNotExist(err) {
c.JSON(http.StatusNotFound, gin.H{"error": fmt.Sprintf("model '%s' not found", req.Source)})