fix(shared): decode local repository paths from file:// clone URLs

Closed
BR
2mo ago
+124-3

Fixes #1689

getRepoPath returned new URL(cloneUrl).pathname for local (file://) repositories. That value is percent-encoded, so a repo at /Users/me/Code Projects/my repo was looked up at /Users/me/Code%20Projects/my%20repo, which does not exist. The repo was discovered but could not be indexed or browsed. It now uses fileURLToPath(cloneUrl), which returns the real on-disk path.

Not covered here: # and ? in a path still break, because the clone URL itself is built without encoding. That is a separate change.

How I verified it

New tests in packages/shared/src/utils.test.ts (a path with spaces, a path with é and brackets, and a plain path):

  • On main (b4931510), 2 fail. For example path is /Users/me/Code%20Projects/my%20repo where /Users/me/Code Projects/my repo is expected.
  • With the fix, the whole shared suite passes (9 files, 142 tests), and tsc --noEmit -p packages/shared is clean.

A reviewer can confirm it by adding a local repo connection for a directory with a space in its name and indexing it.

AI disclosure: an AI coding agent working for the breken-ai account found, fixed and tested this.

🤖 Generated with Claude Code


[!NOTE]
Low Risk
Localized path resolution for local genericGitHost repos with backward-compatible fallbacks; no auth or remote clone behavior changes.

Overview
Fixes local generic-git repos whose on-disk paths include spaces, non-ASCII characters, or other segments that must be percent-encoded in a file:// URL. Discovery could succeed, but indexing and browsing failed because the stored path was wrong.

Write path: new local repos get cloneUrl from pathToFileURL(repoPath) instead of concatenating file:// with a raw path.

Read path: getRepoPath decodes file:// clone URLs with fileURLToPath rather than using URL.pathname (which stays percent-encoded). It keeps legacy behavior when the decoded path is missing but the old literal pathname exists, when URL parsing throws on invalid escapes like %2F, and normalizes Windows /C:/... pathnames.

Tests cover spaces, Unicode, Windows legacy URLs, and literal % in directory names; the changelog records the fix.

Reviewed by Cursor Bugbot for commit 0dc961916e2c336d0078378deb582448defc3770. Bugbot is set up for automated code reviews on this repo. Configure here.


Summary by cubic

Fixes local repository lookup for file:// clone URLs so repos with spaces, non-ASCII characters, or other percent-encodable segments in their path can be indexed and browsed.

Bug Fixes

  • New clone URLs are stored via pathToFileURL(), and getRepoPath decodes them with fileURLToPath() instead of returning the percent-encoded URL.pathname.
  • Legacy records that stored file:// plus a raw path fall back to the literal pathname when the decoded path doesn't exist, so valid percent escapes in directory names and invalid escapes like %2F still resolve.
  • Legacy Windows URLs like /C:/... are normalized to drive-letter paths on Windows.
  • Paths containing # or ? remain unsupported since the clone URL itself isn't encoded.
  • Tests and a changelog entry cover new, legacy, and Windows path shapes.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed local repository paths containing spaces, non-ASCII characters, or literal percent-encoded text so they resolve correctly and can be indexed.
    • Improved handling of legacy Windows file paths, including paths with a drive-letter prefix, to ensure they resolve to the intended local repository.