Skip to content

Percent-encode pipe character in URL paths#3764

Open
Mr-Neutr0n wants to merge 1 commit intoencode:masterfrom
Mr-Neutr0n:fix-pipe-encoding-in-path
Open

Percent-encode pipe character in URL paths#3764
Mr-Neutr0n wants to merge 1 commit intoencode:masterfrom
Mr-Neutr0n:fix-pipe-encoding-in-path

Conversation

@Mr-Neutr0n
Copy link

Fixes #3565.

The | character wasn't being percent-encoded in path segments, even though it's not a valid pchar per RFC 3986. Some servers reject or redirect URLs that contain an unencoded pipe — which is what the original reporter ran into (getting a 301 redirect when switching from requests to httpx).

This removes | (U+007C) from the PATH_SAFE set so it gets encoded as %7C, matching the behavior of Python's urllib.parse.quote and the requests library.

The WHATWG URL spec technically allows | unencoded in paths, so I've skipped the 3 WHATWG conformance test cases that expect an unencoded pipe in the pathname. Added a regression test covering both raw_path and path properties.

the | character was not being percent-encoded in path segments,
even though it's not a valid pchar per RFC 3986. this caused
issues with servers that reject or redirect URLs with unencoded
pipes. now | gets encoded as %7C in paths, matching the behavior
of Python's urllib and the requests library.
@Mr-Neutr0n Mr-Neutr0n mentioned this pull request Feb 13, 2026
1 task
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.

Percent encoding | in paths

1 participant