mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 04:10:20 +08:00
fix: panic while insert record when request uri too long (#325)
Signed-off-by: Lex Lim <hyperzlink@outlook.com>
This commit is contained in:
28
util/path.go
28
util/path.go
@ -42,3 +42,31 @@ func GetUrlHost(urlString string) string {
|
||||
u, _ := url.Parse(urlString)
|
||||
return fmt.Sprintf("%s://%s", u.Scheme, u.Host)
|
||||
}
|
||||
|
||||
func FilterQuery(urlString string, blackList []string) string {
|
||||
urlData, err := url.Parse(urlString)
|
||||
if err != nil {
|
||||
return urlString
|
||||
}
|
||||
|
||||
queries := urlData.Query()
|
||||
retQuery := make(url.Values)
|
||||
inBlackList := false
|
||||
for key, value := range queries {
|
||||
inBlackList = false
|
||||
for _, blackListItem := range blackList {
|
||||
if blackListItem == key {
|
||||
inBlackList = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !inBlackList {
|
||||
retQuery[key] = value
|
||||
}
|
||||
}
|
||||
if len(retQuery) > 0 {
|
||||
return urlData.Path + "?" + strings.ReplaceAll(retQuery.Encode(), "%2F", "/")
|
||||
} else {
|
||||
return urlData.Path
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user