Skip to content

Commit 796eefe

Browse files
committed
test(tools): stop the preserves-whitespace branch swallowing a rejection
cubic found the whitespace assertion tolerated a throw unconditionally, even in the branch whose docstring says padding must survive to the wire. A regression that made safeUrlPath trim or refuse padding would have left the suite green — the same assertion-that-cannot-fail class this file exists to prevent. The tolerance now applies only to ordinary ids, where refusing padding is an equally correct outcome. Verified: pointing the Supabase storage key at a guard that refuses padding now fails the assertion instead of passing.
1 parent 6dace54 commit 796eefe

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

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

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -537,22 +537,35 @@ export function itResistsTraversal(
537537
return
538538
}
539539

540+
if (preservesWhitespace) {
541+
/**
542+
* No tolerance for a throw here. This branch asserts that padding
543+
* *survives*, so a rejection contradicts it outright — swallowing that
544+
* would let `safeUrlPath` regress to trimming or refusing while the suite
545+
* stayed green, which is the failure mode this file exists to prevent.
546+
*/
547+
const url = buildUrl(tool, paramName, padded, context)
548+
549+
expect(url.pathname.startsWith(basePath)).toBe(true)
550+
expect(decodeURIComponent(url.pathname)).toBe(
551+
decodeURIComponent(baselinePath).split(PROBE_ID).join(padded)
552+
)
553+
return
554+
}
555+
556+
/**
557+
* For an ordinary id, refusing padding outright is an equally correct
558+
* outcome — `validateDatabaseIdentifier` guards Supabase's `table` and
559+
* admits no whitespace at all — so the assertion is "same path or no path".
560+
*/
540561
let url: URL
541562
try {
542563
url = buildUrl(tool, paramName, padded, context)
543564
} catch {
544565
return
545566
}
546567

547-
if (!preservesWhitespace) {
548-
expect(url.pathname).toBe(baselinePath)
549-
return
550-
}
551-
552-
expect(url.pathname.startsWith(basePath)).toBe(true)
553-
expect(decodeURIComponent(url.pathname)).toBe(
554-
decodeURIComponent(baselinePath).split(PROBE_ID).join(padded)
555-
)
568+
expect(url.pathname).toBe(baselinePath)
556569
})
557570
}
558571

0 commit comments

Comments
 (0)