Skip to content

fix: Escape file paths in contents methods - #4721

Merged
gmlewis merged 3 commits into
google:masterfrom
ranjithguggilla:fix/escape-contents-file-paths
Nov 22, 2026
Merged

gmlewis merged 3 commits into
google:masterfrom
ranjithguggilla:fix/escape-contents-file-paths

Conversation

@ranjithguggilla

@ranjithguggilla ranjithguggilla commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4720.

CreateFile, UpdateFile and DeleteFile insert the file path into the request URL without escaping it, unlike GetContents. A path containing # or ? is cut at that character, so the request goes to a different file (docs/C#.md becomes docs/C), and a path with a bare % fails with a URL parse error.

This escapes the path the same way GetContents already 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.sh and script/test.sh pass.

Note: a caller that pre-escaped the path as a workaround will now have it escaped twice.

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.
@google-cla

google-cla Bot commented Nov 17, 2026

Copy link
Copy Markdown

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.

@gmlewis gmlewis added the NeedsReview PR is awaiting a review before merging. label Nov 17, 2026
@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.64%. Comparing base (5d83c3d) to head (7195dd2).
⚠️ Report is 1 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread github/repos_contents.go Resolved
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.
Comment thread github/repos_contents.go Resolved
Comment thread github/repos_contents.go Resolved
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 gmlewis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @ranjithguggilla!
LGTM.
Awaiting second LGTM+Approval from any other contributor to this repo before merging.

cc: @stevehipwell - @Not-Dhananjay-Mishra

@Not-Dhananjay-Mishra Not-Dhananjay-Mishra left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@gmlewis gmlewis removed the NeedsReview PR is awaiting a review before merging. label Nov 22, 2026
@gmlewis
gmlewis merged commit 5c5bbe8 into google:master Nov 22, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File mutation methods do not escape paths

4 participants