Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d4fb951

Browse files
committed
chore: implement wildcard style matching for param values
1 parent aca699c commit d4fb951

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

coderd/database/queries.sql.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/workspaces.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ WHERE
222222
build_params
223223
ON
224224
LOWER(workspace_build_parameters.name) = build_params.name AND
225-
LOWER(workspace_build_parameters.value) = build_params.value AND
225+
LOWER(workspace_build_parameters.value) LIKE build_params.value AND
226226
workspace_build_parameters.workspace_build_id = latest_build.id
227227
)
228228
ELSE true

coderd/searchquery/search.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,19 @@ func Workspaces(query string, page codersdk.Pagination, agentInactiveDisconnectT
151151
filter.HasParam = append(filter.HasParam, p.name)
152152
continue
153153
}
154+
155+
// In postgres, '%' is the wildcard character for matching. But * is a more commonly
156+
// used character.
157+
// First escape any '%' characters in the value to treat them as literals.
158+
valueMatch := strings.ReplaceAll(*p.value, "%", `\%`)
159+
// Then replace wildcards with the '%' character. If someone wants the
160+
// literal '*' character... then we will have to implement something.
161+
// If we have to implement escaping '*', then we have to implement escaping the
162+
// escape character as well, which might actually be used in a value.
163+
// Let's avoid the complexity until we need it.
164+
valueMatch = strings.ReplaceAll(valueMatch, "*", "%")
154165
filter.ParamNames = append(filter.ParamNames, p.name)
155-
filter.ParamValues = append(filter.ParamValues, *p.value)
166+
filter.ParamValues = append(filter.ParamValues, valueMatch)
156167
}
157168

158169
parser.ErrorExcessParams(values)

0 commit comments

Comments
 (0)