mirror of https://github.com/coder/coder.git
chore: implement wildcard style matching for param values
This commit is contained in:
parent
2bcdbd93ec
commit
9618597965
|
@ -11990,7 +11990,7 @@ WHERE
|
|||
build_params
|
||||
ON
|
||||
LOWER(workspace_build_parameters.name) = build_params.name AND
|
||||
LOWER(workspace_build_parameters.value) = build_params.value AND
|
||||
LOWER(workspace_build_parameters.value) LIKE build_params.value AND
|
||||
workspace_build_parameters.workspace_build_id = latest_build.id
|
||||
)
|
||||
ELSE true
|
||||
|
|
|
@ -222,7 +222,7 @@ WHERE
|
|||
build_params
|
||||
ON
|
||||
LOWER(workspace_build_parameters.name) = build_params.name AND
|
||||
LOWER(workspace_build_parameters.value) = build_params.value AND
|
||||
LOWER(workspace_build_parameters.value) LIKE build_params.value AND
|
||||
workspace_build_parameters.workspace_build_id = latest_build.id
|
||||
)
|
||||
ELSE true
|
||||
|
|
|
@ -151,8 +151,19 @@ func Workspaces(query string, page codersdk.Pagination, agentInactiveDisconnectT
|
|||
filter.HasParam = append(filter.HasParam, p.name)
|
||||
continue
|
||||
}
|
||||
|
||||
// In postgres, '%' is the wildcard character for matching. But * is a more commonly
|
||||
// used character.
|
||||
// First escape any '%' characters in the value to treat them as literals.
|
||||
valueMatch := strings.ReplaceAll(*p.value, "%", `\%`)
|
||||
// Then replace wildcards with the '%' character. If someone wants the
|
||||
// literal '*' character... then we will have to implement something.
|
||||
// If we have to implement escaping '*', then we have to implement escaping the
|
||||
// escape character as well, which might actually be used in a value.
|
||||
// Let's avoid the complexity until we need it.
|
||||
valueMatch = strings.ReplaceAll(valueMatch, "*", "%")
|
||||
filter.ParamNames = append(filter.ParamNames, p.name)
|
||||
filter.ParamValues = append(filter.ParamValues, *p.value)
|
||||
filter.ParamValues = append(filter.ParamValues, valueMatch)
|
||||
}
|
||||
|
||||
parser.ErrorExcessParams(values)
|
||||
|
|
Loading…
Reference in New Issue