1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 02:17:05 +00:00

add Configuration.URLParamSeparator

This commit is contained in:
Gerasimos (Makis) Maropoulos
2022-11-29 10:49:49 +02:00
parent 29c29e79e5
commit 8cf891ff25
7 changed files with 55 additions and 12 deletions

View File

@@ -40,7 +40,8 @@ type ConfigurationReadOnly interface {
GetDisableAutoFireStatusCode() bool
// GetResetOnFireErrorCode returns the ResetOnFireErrorCode field.
GetResetOnFireErrorCode() bool
// GetURLParamSeparator returns URLParamSeparator field.
GetURLParamSeparator() *string
// GetEnableOptimizations returns the EnableOptimizations field.
GetEnableOptimizations() bool
// GetEnableProtoJSON returns the EnableProtoJSON field.

View File

@@ -1519,7 +1519,7 @@ func (ctx *Context) URLParam(name string) string {
// URLParamSlice a shortcut of ctx.Request().URL.Query()[name].
// Like `URLParam` but it returns all values instead of a single string separated by commas.
// Returns the values of a url query of the given "name" as string slice, e.g.
// ?name=john&name=doe&name=kataras will return [ john doe kataras].
// ?names=john&names=doe&names=kataras and ?names=john,doe,kataras will return [ john doe kataras].
//
// Note that, this method skips any empty entries.
//
@@ -1530,14 +1530,23 @@ func (ctx *Context) URLParamSlice(name string) []string {
if n == 0 {
return values
}
sepPtr := ctx.app.ConfigurationReadOnly().GetURLParamSeparator()
normalizedValues := make([]string, 0, n)
for _, v := range values {
if v == "" {
continue
}
if sepPtr != nil {
if sep := *sepPtr; sep != "" {
values := strings.Split(v, sep)
normalizedValues = append(normalizedValues, values...)
continue
}
}
normalizedValues = append(normalizedValues, v)
}