Skip to content

Conversation

brendan-kellam
Copy link
Contributor

@brendan-kellam brendan-kellam commented Sep 1, 2025

Fixes #482

Summary by CodeRabbit

  • Bug Fixes

    • Fixed navigation and browsing for URLs containing percent-encoded characters (e.g., %25, %2F, %40), ensuring correct repo/revision detection and path handling in file and directory views.
    • Improved reliability when opening encoded paths, reducing decoding-related errors.
  • Documentation

    • Updated changelog with an Unreleased entry describing the fix for paths with percentage symbols.
  • Tests

    • Added tests covering URL decoding in both repository/revision and path segments to ensure accurate parsing and display.

Copy link

coderabbitai bot commented Sep 1, 2025

Walkthrough

Adjusts URL-decoding responsibilities in browse path parsing: page stops pre-decoding the catch-all path; utils now decodes the repo/revision segment. Adds tests covering percent-encoded characters (%) in both repo/revision and blob path. Updates changelog to document the fix.

Changes

Cohort / File(s) Summary
Browse parsing logic
packages/web/src/app/[domain]/browse/hooks/utils.ts, packages/web/src/app/[domain]/browse/hooks/utils.test.ts
Decode repo/revision segment via decodeURIComponent before splitting at '@'. Add tests verifying decoding for %25, %2F in blob path and %40 in revision.
Page routing component
packages/web/src/app/[domain]/browse/[...path]/page.tsx
Remove decodeURIComponent on joined catch-all path; pass raw encoded path to parser.
Changelog
CHANGELOG.md
Add Unreleased Fixed note for navigation to percent-encoded paths.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor U as User
    participant R as Next.js Route (page.tsx)
    participant P as getBrowseParamsFromPathParam (utils.ts)
    participant V as View (Code/Tree Panel)

    U->>R: Navigate to /browse/...@REV/-/(blob|tree)/<encoded path>
    note right of R: _No pre-decoding of catch-all path_
    R->>P: parse(_rawPath.join('/'))  (encoded)
    note over P: decode repo/revision segment<br/>interpret path & pathType
    P-->>R: { repoName, revisionName, path, pathType }
    alt pathType == "blob"
        R->>V: Render CodePreviewPanel
    else pathType == "tree"
        R->>V: Render TreePreviewPanel
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
Fix SSR failure when navigating to paths containing percent symbols [%name%] (#482)
Ensure correct decoding across repo@revision and blob/tree path segments (#482)
Maintain existing browse control flow and rendering behavior (#482)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation

Possibly related PRs

Poem

A carrot of code in a burrow of bytes,
I hop through paths with percent signs and lights.
No SSR stumbles, no 500 cries—
Decoding my veggies, to render the skies.
Thump-thump, ship it! 🥕✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bkellam/fix_482

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

This comment has been minimized.

@brendan-kellam
Copy link
Contributor Author

@coderabbitai review

Copy link

coderabbitai bot commented Sep 1, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
CHANGELOG.md (1)

12-12: Clarify the note (tiny wording nit).

Consider “percent symbols (%)” and reference the issue for quick traceability.

-- Fix error when navigating to paths with percentage symbols. [#485](https://github.com/sourcebot-dev/sourcebot/pull/485)
+- Fix SSR error when navigating to paths with percent symbols (%). [#485](https://github.com/sourcebot-dev/sourcebot/pull/485), fixes #482
packages/web/src/app/[domain]/browse/hooks/utils.ts (2)

8-8: Harden decoding to avoid URIError on malformed “%” sequences.

If the router or upstream already decoded segments (leaving literal “%”), decodeURIComponent can throw and crash SSR. Use a safe decoder and apply it consistently here (and to the tree/blob path below).

Apply within this hunk:

-    const repoAndRevisionPart = decodeURIComponent(pathParam.substring(0, sentinelIndex));
+    const repoAndRevisionPart = safeDecodeURIComponent(pathParam.substring(0, sentinelIndex));

Also add (outside this hunk) and use for the tree/blob path:

// place near top of file
const safeDecodeURIComponent = (s: string) => {
  try { return decodeURIComponent(s) } catch { return s }
};

// replace decodeURIComponent(...) in both 'tree' and 'blob' cases with safeDecodeURIComponent(...)

And add a test that passes an already-decoded percent path:

it('should handle already-decoded % in blob path', () => {
  const r = getBrowseParamsFromPathParam('github.com/sourcebot-dev/zoekt@HEAD/-/blob/%hello%/world.c');
  expect(r).toEqual({
    repoName: 'github.com/sourcebot-dev/zoekt',
    revisionName: 'HEAD',
    path: '%hello%/world.c',
    pathType: 'blob',
  });
});

18-18: Comment typo.

“decodedURIComponent” → “decodeURIComponent”; “incase” → “in case”.

packages/web/src/app/[domain]/browse/hooks/utils.test.ts (1)

102-110: Tests cover the core regressions—add one more for already-decoded “%”.

The new cases are solid. Add a case where the blob path contains raw “%” to ensure SSR doesn’t blow up if upstream hands us decoded segments (pairs well with a safe decoder).

Example:

it('should not throw with raw % in path', () => {
  const r = getBrowseParamsFromPathParam('github.com/sourcebot-dev/zoekt@HEAD/-/blob/%hello%/world.c');
  expect(r.path).toBe('%hello%/world.c');
});

Also applies to: 112-120

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2241217 and c982b14.

📒 Files selected for processing (4)
  • CHANGELOG.md (1 hunks)
  • packages/web/src/app/[domain]/browse/[...path]/page.tsx (1 hunks)
  • packages/web/src/app/[domain]/browse/hooks/utils.test.ts (1 hunks)
  • packages/web/src/app/[domain]/browse/hooks/utils.ts (1 hunks)
🔇 Additional comments (1)
packages/web/src/app/[domain]/browse/[...path]/page.tsx (1)

22-22: Good move—avoid premature decoding at the page level.

Letting utils handle targeted decoding prevents double-decoding and URIError on literal “%”.

@brendan-kellam brendan-kellam merged commit d4cb532 into main Sep 1, 2025
6 checks passed
@brendan-kellam brendan-kellam deleted the bkellam/fix_482 branch September 1, 2025 15:45
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.

[bug] Sourcebot SSR fails on files with percent symbols
1 participant