Repository navigation
fix: Escape file paths in contents methods - #4721
Conversation
CreateFile, UpdateFile, and DeleteFile put the file path into the request URL without escaping it, unlike GetContents. A path containing '#' or '?' was cut at that character, so the request targeted a different file, and a path containing a bare '%' failed with a URL parse error. Escape the path the same way GetContents does and add a table test covering the three methods.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4721 +/- ##
=======================================
Coverage 98.64% 98.64%
=======================================
Files 204 204
Lines 19159 19162 +3
=======================================
+ Hits 18899 18902 +3
Misses 260 260 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
url.QueryEscape encodes spaces as '+' and slashes as '%2F', which breaks existing contents paths. Keep the GetContents encoding and note it on each contents method.
URL.String prepends ./ when the first segment contains a colon, so release:v1/x was requested as ./release:v1/x. EscapedPath keeps the same encoding without that prefix.
gmlewis
left a comment
There was a problem hiding this comment.
Thank you, @ranjithguggilla!
LGTM.
Awaiting second LGTM+Approval from any other contributor to this repo before merging.
Fixes #4720.
CreateFile,UpdateFileandDeleteFileinsert the file path into the request URL without escaping it, unlikeGetContents. A path containing#or?is cut at that character, so the request goes to a different file (docs/C#.mdbecomesdocs/C), and a path with a bare%fails with a URL parse error.This escapes the path the same way
GetContentsalready does.I added
TestRepositoriesService_filePath_isEscaped, which covers the three methods. Without the source change 12 of its 18 subtests fail; with it they all pass.script/fmt.sh,script/lint.shandscript/test.shpass.Note: a caller that pre-escaped the path as a workaround will now have it escaped twice.