Skip to content

Commit c3aceb6

Browse files
committed
chore(cleanup): use shared escapeLikePattern in list-query and logs filters
1 parent 934f384 commit c3aceb6

3 files changed

Lines changed: 2 additions & 19 deletions

File tree

‎apps/sim/lib/api/list-query.test.ts‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ vi.unmock('drizzle-orm')
1111
import { decimal, integer, PgDialect, pgTable, text, timestamp } from 'drizzle-orm/pg-core'
1212
import {
1313
decimalKey,
14-
escapeLikePattern,
1514
keysetAfter,
1615
listOrderBy,
1716
numberKey,
@@ -34,14 +33,6 @@ function render(fragment: Parameters<PgDialect['sqlToQuery']>[0]) {
3433
return dialect.sqlToQuery(fragment)
3534
}
3635

37-
describe('escapeLikePattern', () => {
38-
it('neutralizes the LIKE wildcards so a caller cannot widen its own match', () => {
39-
expect(escapeLikePattern('100%')).toBe('100\\%')
40-
expect(escapeLikePattern('a_b')).toBe('a\\_b')
41-
expect(escapeLikePattern('back\\slash')).toBe('back\\\\slash')
42-
})
43-
})
44-
4536
describe('searchFilter', () => {
4637
it('binds the caller term as a parameter instead of inlining it into the SQL', () => {
4738
const { sql, params } = render(searchFilter(thing.name, "o'brien; drop table thing --")!)

‎apps/sim/lib/api/list-query.ts‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { escapeLikePattern } from '@sim/utils/string'
12
import {
23
and,
34
asc,
@@ -28,15 +29,6 @@ export type ListSortOrder = (typeof LIST_SORT_ORDERS)[number]
2829
* cursor's values are type-checked against their key before they are bound.
2930
*/
3031

31-
/**
32-
* Escapes LIKE/ILIKE wildcards so `%`, `_`, and `\` in a caller's term match
33-
* themselves. Postgres treats `\` as the default LIKE escape character, so no
34-
* explicit `ESCAPE` clause is needed.
35-
*/
36-
export function escapeLikePattern(value: string): string {
37-
return value.replace(/[\\%_]/g, '\\$&')
38-
}
39-
4032
/**
4133
* Case-insensitive substring predicate for a v2 `search` term, or `undefined`
4234
* when the caller did not search (which drops out of an `and(...)`).

‎apps/sim/lib/logs/public-filters.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { jobExecutionLogs, workflow, workflowExecutionLogs } from '@sim/db/schema'
2+
import { escapeLikePattern } from '@sim/utils/string'
23
import { and, eq, gte, inArray, lte, or, type SQL, sql } from 'drizzle-orm'
3-
import { escapeLikePattern } from '@/lib/api/list-query'
44
import { handledErrorSpanCondition } from '@/lib/logs/handled-errors'
55
import type { PersistedWorkflowExecutionStatus } from '@/lib/logs/types'
66

0 commit comments

Comments
 (0)