fix: consistent url.PathEscape across all Gitea client endpoints #30
Reference in New Issue
Block a user
Delete Branch "fix/consistent-path-escape"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Apply
url.PathEscapeto owner, repo, and sha path segments in all methods that were previously interpolating raw values directly.Problem
Some endpoints (
ListReviews,DeleteReview,GetTimelineReviewCommentID,EditComment) already usedurl.PathEscapefor owner/repo, while others (GetPullRequest,GetPullRequestDiff,GetPullRequestFiles,GetCommitStatuses,GetFileContent,GetFileContentRef,PostReview,ListContents) interpolated raw values. This inconsistency was flagged in PRs #17, #20, and #22.Fix
All methods now consistently escape owner, repo, and sha path segments. The
filepathparameter was already handled byescapePath()(per-segment escaping).Risk
Low — for typical owner/repo names this is a no-op. Only matters for names with special characters (spaces, slashes, unicode). But consistency eliminates an entire class of potential bugs.
Closes #24
Gpt Review
Summary
Consistent use of url.PathEscape on all path segments (owner, repo, sha) across the client code improves correctness and eliminates ambiguity, with low risk and no observable API change for typical input.
Recommendation
APPROVE — This PR brings much-needed consistency and safety to path handling for all endpoints, ensuring that special characters in owner, repo, and sha do not break or misroute requests. All uses were already updated to apply url.PathEscape to these segments where needed, and there are no idiom, API, style, or logic violations. Well-documented, low risk, and CI passes -- merge as is.
Review by gpt
Security Review
Summary
This PR consistently applies url.PathEscape to owner, repo, and sha path segments across endpoints, improving robustness against path injection and encoding inconsistencies. CI has passed and the changes are security-hardening without altering behavior for typical inputs.
Recommendation
APPROVE — The changes reduce the risk of path traversal/injection by uniformly escaping path segments and are aligned with secure URL construction practices. No exploitable issues were introduced. As a future hardening consideration (not required for this PR), you could consider constructing URLs via net/url.URL and path.Join-style segment handling to centralize escaping and reduce string formatting errors. Approve as-is.
Review by security
Sonnet Review
Summary
The changes consistently apply url.PathEscape to owner, repo, and sha path segments across endpoints, aligning with correct URL construction practices. CI passed and the implementation appears correct and low-risk.
Recommendation
APPROVE — This PR improves robustness by uniformly escaping path segments for all affected endpoints, matching existing behavior in other methods. The use of url.PathEscape for path segments and url.QueryEscape for the ref query parameter is appropriate, and the existing escapePath() continues to handle file paths per-segment. With CI passing and no functional regressions apparent, this is ready to merge. As a potential future improvement, consider centralizing URL construction (e.g., helper to build repo-scoped paths) to prevent drift and reduce duplication.
Review by sonnet