Skip to content

fix(studio): encode special characters in database advisor lint links - #45385

Merged
alaister merged 1 commit into
supabase:masterfrom
oniani1:fix/studio-linter-encode-uri
May 4, 2026
Merged

alaister merged 1 commit into
supabase:masterfrom
oniani1:fix/studio-linter-encode-uri

Conversation

@oniani1

@oniani1 oniani1 commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor

The link builders in apps/studio/components/interfaces/Linter/Linter.utils.tsx interpolate metadata.schema and metadata.name directly into URL query strings. A schema or table name with &, =, +, or # breaks the destination filter on the linked page because URLSearchParams stops at the bare & and decodes + to a space.

The public_bucket_allows_listing lint at line 338 already wraps bucket_id in encodeURIComponent. The other 15 builders did not. This wraps each metadata?.schema and metadata?.name interpolation with encodeURIComponent(value ?? '') to match.

Added Linter.utils.test.tsx that constructs links with a schema a&b=c and a name d e+f and asserts URLSearchParams round-trips them. The bucket precedent is also covered.

Closes #45384

Summary by CodeRabbit

  • Bug Fixes

    • Improved URL encoding for navigation links in the linter interface to ensure proper handling of special characters in database, schema, and table names.
  • Tests

    • Added test coverage for URL generation functionality in the linter utility.

@oniani1
oniani1 requested a review from a team as a code owner April 29, 2026 20:15
@vercel

vercel Bot commented Apr 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
studio-self-hosted Ready Ready Preview, Comment May 4, 2026 1:31pm
studio-staging Ready Ready Preview, Comment May 4, 2026 1:31pm
zone-www-dot-com Ready Ready Preview, Comment, Open in v0 May 4, 2026 1:31pm
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored May 4, 2026 1:31pm
design-system Skipped Skipped May 4, 2026 1:31pm
docs Skipped Skipped May 4, 2026 1:31pm
learn Skipped Skipped May 4, 2026 1:31pm
ui-library Skipped Skipped May 4, 2026 1:31pm

Request Review

@vercel

vercel Bot commented Apr 29, 2026

Copy link
Copy Markdown

@oniani1 is attempting to deploy a commit to the Supabase Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for contributing to Supabase! ❤️ Our team will review your PR.

A few tips for a smoother review process:

  • If you have a local version of the repo, run pnpm run format to make sure formatting checks pass.
  • Once we've reviewed your PR, please don't trivially merge master (don't click Update branch if there are no merge conflicts to be fixed). This invalidates any pre-merge checks we've run.

@coderabbitai

coderabbitai Bot commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: b839e0fa-7345-4c7c-9d1c-e2260835389d

📥 Commits

Reviewing files that changed from the base of the PR and between d1ec069 and cb45f18.

📒 Files selected for processing (2)
  • apps/studio/components/interfaces/Linter/Linter.utils.test.tsx
  • apps/studio/components/interfaces/Linter/Linter.utils.tsx

📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
Link Generator Updates
apps/studio/components/interfaces/Linter/Linter.utils.tsx
Wraps metadata values (schema, table, search, filter) with encodeURIComponent() and defaults to empty string in link generators for database indexes, auth policies, functions, extensions, and editor routes.
Test Suite
apps/studio/components/interfaces/Linter/Linter.utils.test.tsx
New Vitest suite validating URL encoding of metadata parameters with special characters (&, =, +, #, /, spaces) in lint link generation, including dedicated tests for bucket path encoding.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A fix for the ampersands that broke our links,
Special characters now encoded in a wink,
Plus signs, equals, hashes all contained,
The query strings are safely maintained! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: encoding special characters in database advisor lint links.
Description check ✅ Passed The description is complete, explaining the problem, solution, and including a reference to the test file added. It lacks the template format but contains all necessary information.
Linked Issues check ✅ Passed The PR fully addresses the linked issue #45384 by encoding schema and table name values in URL query strings using encodeURIComponent, and adds comprehensive test coverage.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing URL encoding in Linter link builders and adding corresponding tests; no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@adityakrmishra adityakrmishra left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_listing pattern as a blueprint, which is a great way to maintain codebase consistency.
  • Robust Testing: The choice of trickySchema and trickyName in 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 ?? '')}`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@alaister alaister left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Thanks, @oniani1!

@alaister
alaister merged commit a95b6f9 into supabase:master May 4, 2026
21 of 24 checks passed
@github-actions

github-actions Bot commented May 4, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

No experiments to report

charislam pushed a commit that referenced this pull request May 14, 2026
…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.

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/45846)

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
charislam pushed a commit that referenced this pull request May 14, 2026
… 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.

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/45851)

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
charislam pushed a commit that referenced this pull request May 14, 2026
…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.

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/45849)

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Database Advisor lint links don't encode special characters in schema or table names

3 participants