-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
bug V1Bug related to Pydantic V1.XBug related to Pydantic V1.X
Description
Checks
- I added a descriptive title to this issue
- I have searched (google, github) for similar issues and couldn't find anything
- I have read and followed the docs and still think this is a bug
Bug
Using (AnyUrl, HttpUrl, AnyHttpUrl) build functions results an unusable URL if characters like: :
, /
, ?
, #
, [
,
, ]
, @
exists in the following arguments: user
, password
, path
, query
, fragment
.
In other words these arguments should be Percent-Encoded to work properly and not
produce a Url that have characters that conflicts with the url-spec.
Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())"
:
pydantic version: 1.8.2
pydantic compiled: True
install path: /.../.venv/lib/python3.9/site-packages/pydantic
python version: 3.9.6 (default, Jul 3 2021, 17:50:42) [GCC 7.5.0]
platform: Linux-5.4.0-80-generic-x86_64-with-glibc2.27
optional deps. installed: ['dotenv', 'email-validator', 'typing-extensions']
Example
>>> from pydantic import AnyUrl, HttpUrl, AnyHttpUrl
>>>
>>> AnyUrl.build(
... scheme="ws",
... user="@AwesomeUser",
... password="Pa##w0rd?:/",
... host="localhost",
... port="5000"
...)
'ws://@AwesomeUser:Pa##w0rd?:/@localhost:5000'
>>> # ...
>>> # The same result with `HttpUrl`, `AnyHttpUrl`
The easiest way to percent-encode in Python is to use the urllib.parse.quote
function
simon-liebehenschel
Metadata
Metadata
Assignees
Labels
bug V1Bug related to Pydantic V1.XBug related to Pydantic V1.X