Add URL escaping/unescaping for winhttp URL functions.#353
Open
zooba wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes #351 by making the WinHTTP URL helpers percent-decode userinfo (and host/path where appropriate) and percent-encode user/password when re-assembling URLs, so that HTTP Basic auth credentials with reserved characters (e.g. @ in SAML/SSO emails) are transmitted correctly. The native helpers also keep an "env-var" escape hatch so that %NAME% placeholders are passed through untouched and sanitise_url is updated to mirror that on both the username and password fields.
Changes:
- Introduce native
escape_url_part/unescape_url_parthelpers inwinhttp.cppand rewirewinhttp_urlopen,winhttp_urlsplit, andwinhttp_urlunsplitto decode userinfo/host/path and re-encode credentials, dropping the previousadd_nuls/mutating-URL approach. - Update
sanitise_urlto also preserve%...%-style usernames (not just passwords) and fix a typo where the password check calledstartswithtwice. - Add tests for sanitising encoded credentials, round-tripping encoded userinfo through
unsanitise_url, percent-decoded credentials inextract_url_auth, andurljoinbehavior with%XXsegments.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/_native/winhttp.cpp | Adds escape/unescape helpers, decodes host/path/credentials before use, re-encodes credentials on unsplit, and switches WinHttpCreateUrl away from ICU_ESCAPE. |
| src/manage/urlutils.py | sanitise_url now preserves env-var-style usernames and correctly checks password suffix. |
| tests/test_urlutils.py | Adds sanitise/unsanitise/extract_url_auth cases for percent-encoded userinfo and urljoin cases for encoded path segments. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Fixes #351