Repository navigation
Fix reserved characters in GitHub content file paths - #2198
Merged
martindurant merged 1 commit intoSep 28, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GithubFileSysteminserted file paths into GitHub contents API URLs without encoding them. A#in a filename was treated as a URL fragment,?started a query string, and a literal%23or%2Fwas decoded into a different character. As a result, opening or removing such a file could fail with a 404 or act on a different path.This change percent-encodes the path when building the read, SHA-lookup and delete URLs. Directory separators are left as they are, so nested paths work as before, and names returned by
ls()can now be passed straight toopen()andrm().Branch/ref handling is unchanged. Callers who previously pre-encoded file paths to work around this should now pass literal names.
Tests: a new offline test module patches
requests.Session.send, so Requests still prepares the URLs for real but no network calls are made. It covers#,?, literal%23/%2F, spaces, Unicode and plain names, and deletion with and without a cached SHA. The tests check the exact encoded URL path and the request sequence. The 10 reserved-character cases fail on the base commit, and all 13 pass with the fix. The related spec/core/utils selection passes (306 passed, 129 skipped, 1 xfailed), with one Windows HTTP server teardown warning. Changed-file Ruff 0.14.3 and whitespace checks pass. No live GitHub requests were made by the new tests.