PyGithub icon indicating copy to clipboard operation
PyGithub copied to clipboard

fix: Incorrect url encoding of strings in URLs

Open OscarVanL opened this issue 1 year ago • 6 comments

Fixes https://github.com/PyGithub/PyGithub/issues/3262.

This changes the URL encoding function used for strings in URLs. Currently, this uses urllib.parse.quote, which makes an exclusion of URL-encoding the / character:

urllib.parse.quote(string, safe='/', encoding=None, errors=None) Replace special characters in string using the %xx escape. Letters, digits, and the characters '_.-~' are never quoted. By default, this function is intended for quoting the path section of a URL. The optional safe parameter specifies additional ASCII characters that should not be quoted — its default value is '/'.

The GitHub APIs expect that / should be URL encoded. For example, if my environment name contains / I get a 404 from the GitHub API.

I have modified the call to remove this exclusion for the / character, which causes the environment name to be correctly encoded. I have updated the test cases to provide coverage for this change.

OscarVanL avatar Mar 11 '25 22:03 OscarVanL

Thanks for fixing this. I think all places where we call quote should be fixed. Can you roll this fix out everywhere?

EnricoMi avatar Mar 17 '25 09:03 EnricoMi

I can, but I think I will have trouble updating all the unit test cases.

OscarVanL avatar Mar 17 '25 20:03 OscarVanL

@EnricoMi I've fixed that up for other usages of quote. I skipped cases that related to commit SHAs, as they shouldn't contain any slashes anyway.

I didn't add any new test cases, except of course for the updated Environments API test I originally opened this fix for. I don't have time to setup the required integrations etc to do this. Hopefully the existing tests not failing is a good indication that the change doesn't cause any regressions.

Please double-check what API usages I've updated and if you're satisfied that's correct.

OscarVanL avatar Mar 23 '25 13:03 OscarVanL

Test Results

     8 files  ±0       8 suites  ±0   4m 49s ⏱️ -7s  1 002 tests ±0   1 002 ✅ ±0  0 💤 ±0  0 ❌ ±0  11 091 runs  ±0  11 090 ✅ ±0  1 💤 ±0  0 ❌ ±0 

Results for commit 30637974. ± Comparison against base commit 95f015c8.

:recycle: This comment has been updated with latest results.

github-actions[bot] avatar Apr 09 '25 14:04 github-actions[bot]

It looks like some linting tasks are failing. I've rebased the branch. Can you pull the branch and fix the formatting issues? After that I'm happy to merge this.

JLLeitschuh avatar Apr 14 '25 15:04 JLLeitschuh

@JLLeitschuh Thanks, I ran black and fixed the end of file newlines.

OscarVanL avatar Apr 16 '25 13:04 OscarVanL

:warning: Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

:x: Patch coverage is 70.83333% with 7 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 97.33%. Comparing base (fa8f9df) to head (3063797). :warning: Report is 19 commits behind head on main.

Files with missing lines Patch % Lines
github/Repository.py 80.95% 4 Missing :warning:
github/Team.py 0.00% 3 Missing :warning:
:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3263      +/-   ##
==========================================
+ Coverage   95.69%   97.33%   +1.64%     
==========================================
  Files         165      165              
  Lines       18475    18203     -272     
==========================================
+ Hits        17679    17718      +39     
+ Misses        796      485     -311     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

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

codecov-commenter avatar Jul 30 '25 16:07 codecov-commenter