fix: path-escape file paths and eliminate url package shadowing #17
Reference in New Issue
Block a user
Delete Branch "fix/url-escaping-and-shadow"
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?
Addresses remaining findings from PR #16 review:
escapePath()helper — escapes each segment individually (preserves/as separator, escapes spaces/#/?etc)doGetparameter fromurltoreqURLto avoid shadowingnet/urlpackageAll tests pass,
go vetclean.Summary
Changes correctly escape path segments and avoid net/url shadowing in modified areas. Implementation is idiomatic, error handling is preserved, and CI passed.
Findings
gitea/client.gogitea/client.gogitea/client.goRecommendation
APPROVE — The updates meaningfully improve URL handling by escaping path segments and avoid net/url shadowing where it mattered. With CI passing and no functional issues identified, this is good to merge. Optionally, for follow-up polish, consider standardizing on reqURL naming across all URL-building locals, using http.Method* constants in requests, and clarifying/normalizing leading slashes in escapePath.
Summary
The change correctly introduces escapePath to safely escape file path segments and avoids package shadowing in doGet by renaming the parameter. The modifications are small, targeted, and appear correct; CI passed and go vet is clean.
Findings
gitea/client.gogitea/client.gogitea/client.gogitea/client.goRecommendation
APPROVE — Approve these changes. They fix the important issue of safely escaping file path segments and remove a potential package-shadowing pitfall in doGet. Before merging, consider adding unit tests for escapePath to assert behavior with empty paths, leading/trailing slashes, and already-encoded input, and optionally standardize the request URL local variable name across all URL-building functions for consistency.
Summary
Changes are correct and idiomatic: variable renaming avoids package shadowing, HTTP method constants are used, and file path segments are safely escaped. Added tests for escapePath are appropriate and CI passed.
Recommendation
APPROVE — The PR improves robustness by escaping file path segments with url.PathEscape and clarifies code by avoiding net/url shadowing. Consistent use of http.Method* constants is a nice touch. Tests cover the new helper well, and overall behavior remains clear and correct. No further changes requested.
Summary
The changes correctly avoid shadowing the net/url package, consistently use http.Method* constants, and add a robust escapePath helper with accompanying tests. Code is idiomatic, well-documented, and tests/CI pass.
Findings
gitea/client.gogitea/client.gogitea/client.gogitea/client.gogitea/client_test.goRecommendation
APPROVE — Approve this PR. The rename to reqURL prevents shadowing issues and the new escapePath helper correctly escapes individual path segments. The use of http.Method* is more idiomatic and safer. Consider deciding and documenting the desired behavior for empty path inputs (root) and whether double-encoding already-encoded segments is always desired; if you prefer to avoid double-encoding in some contexts, provide a separate helper or document caller responsibilities. Otherwise, this change is clean and ready to merge.
Summary
Solid improvements: path segments are now correctly escaped, URL variable shadowing is removed, and HTTP method constants are used. Changes are correct and idiomatic; tests pass and CI is green.
Findings
gitea/client.gogitea/client.gogitea/client.gogitea/client.gogitea/client_test.goRecommendation
APPROVE — The refactor successfully avoids net/url shadowing, uses HTTP method constants, and correctly escapes file path segments. Behavior changes in ListContents for empty paths are sensible. I recommend merging as-is. As follow-ups, consider: (1) wrapping doGet errors with contextual messages, (2) optionally PathEscape owner/repo segments for extra robustness, and (3) adding tests to verify empty path handling in ListContents and that path escaping is exercised via the public API methods.
Summary
The changes correctly avoid shadowing the net/url package, introduce a safe escapePath helper to percent-encode individual path segments, and consistently use http.MethodGet/POST. Tests were added for escapePath and CI passed.
Findings
gitea/client.gogitea/client.gogitea/client.gogitea/client_test.goRecommendation
APPROVE — Approve these changes. They fix the url package shadowing and add robust per-segment path escaping with accompanying tests. The escapePath behavior (double-encoding) is documented — ensure callers do not pre-encode paths if that would be undesired. Optionally, add a test for leading-slash inputs to clarify behavior for those cases, and verify the server's expectations for query encoding (QueryEscape vs percent-encoding) for the ref parameter if interoperability issues arise.