DUP-GO-10/11: abs-path dir validation duplicated across worktree and git handlers #48

Closed
opened 2026-05-27 16:57:35 +02:00 by dries · 0 comments
Owner

Summary

The same 5-line block for validating the dir query parameter appears in at least 4 places across two files:

  • internal/server/handlers_worktree.go lines 60–68 (handleWorktreeList)
  • internal/server/handlers_worktree.go lines 95–103 (handleWorktreeDefaultBaseRef)
  • internal/server/handlers_worktree.go lines 128+ (handleWorktreeCreateAndLaunch)
  • internal/server/handlers_git.go lines 93–101 (handleGitDiff)

Duplicated block

dir := r.URL.Query().Get("dir")
if dir == "" { http.Error(w, "dir query parameter is required", http.StatusBadRequest); return }
if !filepath.IsAbs(dir) { http.Error(w, "dir must be an absolute path", http.StatusBadRequest); return }

Additionally, handleWorktreeList and handleWorktreeDefaultBaseRef both duplicate the ResolveRepoRoot error-handling block (~15 lines each).

Fix

  • Extract parseAbsDir(w http.ResponseWriter, r *http.Request) (string, bool) for the dir validation
  • Extract resolveWorktreeRoot(w, r) (string, bool) for the full dir+repoRoot resolution

Effort

Trivial.

## Summary The same 5-line block for validating the `dir` query parameter appears in at least 4 places across two files: - `internal/server/handlers_worktree.go` lines 60–68 (`handleWorktreeList`) - `internal/server/handlers_worktree.go` lines 95–103 (`handleWorktreeDefaultBaseRef`) - `internal/server/handlers_worktree.go` lines 128+ (`handleWorktreeCreateAndLaunch`) - `internal/server/handlers_git.go` lines 93–101 (`handleGitDiff`) ## Duplicated block ```go dir := r.URL.Query().Get("dir") if dir == "" { http.Error(w, "dir query parameter is required", http.StatusBadRequest); return } if !filepath.IsAbs(dir) { http.Error(w, "dir must be an absolute path", http.StatusBadRequest); return } ``` Additionally, `handleWorktreeList` and `handleWorktreeDefaultBaseRef` both duplicate the `ResolveRepoRoot` error-handling block (~15 lines each). ## Fix - Extract `parseAbsDir(w http.ResponseWriter, r *http.Request) (string, bool)` for the dir validation - Extract `resolveWorktreeRoot(w, r) (string, bool)` for the full dir+repoRoot resolution ## Effort Trivial.
dries closed this issue 2026-07-04 19:53:55 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dries/ocman#48
No description provided.