Repository navigation
fix(studio): encode special characters in database advisor lint links - #45385
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
|
@oniani1 is attempting to deploy a commit to the Supabase Team on Vercel. A member of the Team first needs to authorize it. |
|
Thanks for contributing to Supabase! ❤️ Our team will review your PR. A few tips for a smoother review process:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds URL encoding to metadata-derived query parameters in lint link generators to prevent special characters from breaking URL parsing, and introduces a test suite validating the encoding behavior for schema and table names with problematic characters. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
adityakrmishra
left a comment
There was a problem hiding this comment.
I have completed my review of PR #45385. As a student developer diving into the Studio codebase, this was a great learning opportunity for me to see how we handle URL construction and character encoding across different database entities.
Review Summary
The PR is a solid fix for a regression where special characters in schema or table names (like &, =, or +) would break the deep links generated by the Database Advisor/Linter. By not encoding these values, the browser's URLSearchParams was misinterpreting them as parameter delimiters or spaces.
Analysis & Insights
- Consistency: I noticed the PR author used the existing
public_bucket_allows_listingpattern as a blueprint, which is a great way to maintain codebase consistency. - Robust Testing: The choice of
trickySchemaandtrickyNamein the tests is excellent—it specifically targets characters that are often "silent killers" in URL query strings. - Safe Fallbacks: The use of
metadata?.schema ?? ''within the encoder ensures we don't crash on undefined metadata while still producing a valid (though empty) filter string.
Verdict: The code is clean, well-tested, and solves the issue without side effects. I recommend merging.
| icon: <Table2 className="text-foreground-muted" size={15} strokeWidth={1} />, | ||
| link: ({ projectRef, metadata }) => | ||
| `/project/${projectRef}/database/indexes?schema=${metadata?.schema}`, | ||
| `/project/${projectRef}/database/indexes?schema=${encodeURIComponent(metadata?.schema ?? '')}`, |
There was a problem hiding this comment.
As a student learning the codebase, seeing encodeURIComponent applied consistently here to safely handle special characters like & and + is a great lesson in robust URL construction. Really clean fix!
Braintrust eval reportNo experiments to report |
…45846) Closes #45845. ## Summary `GridHeaderActions.tsx` interpolated `table.name` and `table.schema` directly into the policies URL at two `<Link href>` builders. A table or schema containing `&`, `=`, `+`, or `#` corrupted the destination and routed users to the wrong policies filter. Extracts the URL into `getTablePoliciesUrl` in `TableEntity.utils.ts` with `encodeURIComponent` wraps, and replaces both inline interpolations. Same pattern as #45385 (Linter shortcut links). ## Test plan Added four `getTablePoliciesUrl` cases in `TableEntity.utils.test.ts`: plain values, special chars in name, special chars in schema, special chars in both. Existing seven tests in the same file still pass. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Improved Row-Level Security (RLS) policy URL handling in the table editor using a shared utility function for consistent URL building and proper parameter encoding. * **Tests** * Added test coverage for RLS policy URL generation with various parameter combinations and special character handling. [](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/45846) <!-- end of auto-generated comment: release notes by coderabbit.ai -->
… search params (#45851) Closes #45850. ## Summary `TriggerList`, `EventTriggerList`, and `FunctionList` built cross-links between the database triggers and functions pages by interpolating user-controlled identifiers directly into the URL query string. A function or schema name containing `&`, `=`, `+`, or `#` corrupted the destination filter and routed users to the wrong row. Adds `getDatabaseFunctionsHref` to `TriggerList.utils` (used by both `TriggerList` and `EventTriggerList`) and a new `getDatabaseTriggersHref` in `FunctionList.utils`, both with `encodeURIComponent` wraps. Replaces the three inline interpolations. `FunctionList` only has a single search param (no schema) because the link filters by function name only, so its helper takes one less argument. Same pattern as #45385. ## Test plan Added `TriggerList.utils.test.ts` covering `getDatabaseFunctionsHref` (plain, special chars in name, special chars in schema, both, undefined inputs) and `FunctionList.utils.test.ts` covering `getDatabaseTriggersHref` (plain, special chars in name, plus signs and spaces, undefined inputs). Nine tests total. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Improved database navigation links for functions and triggers by standardizing link generation through centralized utility functions. This ensures consistent URL encoding and parameter handling across the application. * **Tests** * Added comprehensive test coverage for database navigation link utilities, including edge cases with special characters and empty parameters. [](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/45851) <!-- end of auto-generated comment: release notes by coderabbit.ai -->
…inks (#45849) Closes #45847. ## Summary `ProjectNeedsSecuringView.tsx` built the `View policies` href on the first-time security gate by interpolating `table.schema` and `table.name` directly into the URL. A table or schema containing `&`, `=`, `+`, or `#` corrupted the destination and routed the user to the wrong policies filter on what is meant to be a guided onboarding flow. Extracts the URL into `getTablePoliciesHref` in `ProjectNeedsSecuring.utils.ts` with `encodeURIComponent` wraps, and replaces the inline interpolation. Same pattern as #45385. ## Test plan Added `ProjectNeedsSecuring.utils.test.ts` covering `getTablePoliciesHref` (plain values, special chars in name, special chars in schema, both, undefined inputs) and pulling in the previously-untested `getTableKey`, `formatRlsDescription`, `sortTables`, and `buildSecurityPromptMarkdown` utilities. Ten tests total. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Added comprehensive test coverage for security utilities, including URL construction, formatting, sorting, and markdown report generation. * **Refactor** * Extracted URL building logic into a centralized utility function for improved consistency and maintainability. [](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/45849) <!-- end of auto-generated comment: release notes by coderabbit.ai -->
The link builders in
apps/studio/components/interfaces/Linter/Linter.utils.tsxinterpolatemetadata.schemaandmetadata.namedirectly into URL query strings. A schema or table name with&,=,+, or#breaks the destination filter on the linked page becauseURLSearchParamsstops at the bare&and decodes+to a space.The
public_bucket_allows_listinglint at line 338 already wrapsbucket_idinencodeURIComponent. The other 15 builders did not. This wraps eachmetadata?.schemaandmetadata?.nameinterpolation withencodeURIComponent(value ?? '')to match.Added
Linter.utils.test.tsxthat constructs links with a schemaa&b=cand a named e+fand assertsURLSearchParamsround-trips them. The bucket precedent is also covered.Closes #45384
Summary by CodeRabbit
Bug Fixes
Tests