Fetch the repository succeeded.
package catalog
import (
"net/http"
"net/url"
"regexp"
"strings"
"github.com/rancher/norman/httperror"
"github.com/rancher/norman/types"
)
var (
controlChars = regexp.MustCompile("[[:cntrl:]]")
controlEncoded = regexp.MustCompile("%[0-1][0-9,a-f,A-F]")
)
func Validator(request *types.APIContext, schema *types.Schema, data map[string]interface{}) error {
if pathURL, _ := data["url"].(string); pathURL != "" {
if err := validateURL(pathURL); err != nil {
return err
}
if u, err := url.Parse(pathURL); err == nil {
u.Scheme = strings.ToLower(u.Scheme) // git commands are case-sensitive
data["url"] = u.String()
}
return nil
} else if request.Method == http.MethodPost {
return httperror.NewAPIError(httperror.MissingRequired, "Catalog URL not specified")
}
return nil
}
func validateURL(pathURL string) error {
if controlChars.FindStringIndex(pathURL) != nil || controlEncoded.FindStringIndex(pathURL) != nil {
return httperror.NewAPIError(httperror.InvalidBodyContent, "Invalid characters in catalog URL")
}
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。