Skip to content

Commit 475eb21

Browse files
committed
refactor(tools): use #7262's strictUrlPathSegment and delete the local copy
#7262 landed d2c74d7, defining strictUrlPathSegment and strictEncodedUrlPathSegment in url-path.ts to refuse padded identifiers on state-changing requests. That is the rule this branch introduced locally while the two PRs were in flight, so the duplication collapses now that the rebase brings it in: tools/strict-url-path.ts is deleted and its four consumers import from @/tools/url-path. Their assertUnpadded is slightly better than the local version — an all-whitespace value falls through to safeUrlPathSegment and reports "is required" rather than a padding error, which names the real problem. strictCanonicalBigQueryId now derives from their guard too, so the body value and the path value share one rule rather than two. The error text changed from "cannot have" to "must not have leading or trailing whitespace", and four assertions failed on the rebase because they pin the exact text. They are updated to the new wording rather than loosened — that precision is the property that caught this and two earlier upstream changes.
1 parent 990a967 commit 475eb21

8 files changed

Lines changed: 9 additions & 77 deletions

File tree

apps/sim/tools/__tests__/path-safety-matcher.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import { namesParam } from '@/tools/__tests__/path-safety'
1414

1515
describe('namesParam', () => {
1616
it.each([
17-
['projectId cannot have leading or trailing whitespace', 'projectId'],
18-
['signRequestId cannot have leading or trailing whitespace', 'signRequestId'],
17+
['projectId must not have leading or trailing whitespace', 'projectId'],
18+
['signRequestId must not have leading or trailing whitespace', 'signRequestId'],
1919
['bucket cannot contain a path separator', 'bucket'],
2020
['path cannot contain an empty or whitespace-only path segment', 'path'],
2121
['tableId cannot be "." (path traversal is not allowed)', 'tableId'],

apps/sim/tools/box_sign/cancel_request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { strictUrlPathSegment } from '@/tools/strict-url-path'
21
import type { ToolConfig } from '@/tools/types'
2+
import { strictUrlPathSegment } from '@/tools/url-path'
33
import type { BoxSignCancelRequestParams, BoxSignResponse } from './types'
44
import { SIGN_REQUEST_OUTPUT_PROPERTIES } from './types'
55

apps/sim/tools/box_sign/get_request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { strictUrlPathSegment } from '@/tools/strict-url-path'
21
import type { ToolConfig } from '@/tools/types'
2+
import { strictUrlPathSegment } from '@/tools/url-path'
33
import type { BoxSignGetRequestParams, BoxSignResponse } from './types'
44
import { SIGN_REQUEST_OUTPUT_PROPERTIES } from './types'
55

apps/sim/tools/box_sign/path_safety.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe('a padded signRequestId cannot become a successful cancellation', () =>
110110
accessToken: 't',
111111
signRequestId: PADDED,
112112
})
113-
).toThrow(/signRequestId cannot have leading or trailing whitespace/)
113+
).toThrow(/signRequestId must not have leading or trailing whitespace/)
114114
})
115115

116116
it.each(STATE_CHANGING)('$name still accepts the unpadded id', ({ tool }) => {

apps/sim/tools/box_sign/resend_request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { strictUrlPathSegment } from '@/tools/strict-url-path'
21
import type { ToolConfig, ToolResponse } from '@/tools/types'
2+
import { strictUrlPathSegment } from '@/tools/url-path'
33
import type { BoxSignResendRequestParams } from './types'
44

55
export const boxSignResendRequestTool: ToolConfig<BoxSignResendRequestParams, ToolResponse> = {

apps/sim/tools/google_bigquery/path_safety.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ describe('a padded projectId cannot become a successful destructive request', ()
261261
datasetId: 'prod_dataset',
262262
tableId: 'prod_table',
263263
})
264-
).toThrow(/projectId cannot have leading or trailing whitespace/)
264+
).toThrow(/projectId must not have leading or trailing whitespace/)
265265
})
266266

267267
it.each(DESTRUCTIVE)('$name still accepts the unpadded id', ({ tool }) => {

apps/sim/tools/google_bigquery/utils.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { assertNoSurroundingWhitespace, strictUrlPathSegment } from '@/tools/strict-url-path'
2-
import { safeUrlPathSegment } from '@/tools/url-path'
1+
import { safeUrlPathSegment, strictUrlPathSegment } from '@/tools/url-path'
32

43
/**
54
* Returns the canonical, unencoded form of an identifier that appears in both
@@ -37,8 +36,7 @@ export function strictCanonicalBigQueryId(
3736
value: string | number | bigint,
3837
paramName: string
3938
): string {
40-
assertNoSurroundingWhitespace(value, paramName)
41-
return canonicalBigQueryId(value, paramName)
39+
return decodeURIComponent(strictUrlPathSegment(value, paramName))
4240
}
4341

4442
/**

apps/sim/tools/strict-url-path.ts

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)