8000 *Url.build functions doesn't percent-encode arguments · Issue #3061 · pydantic/pydantic · GitHub
[go: up one dir, main page]

Skip to content
*Url.build functions doesn't percent-encode arguments #3061
@faresbakhit

Description

@faresbakhit

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug V1Bug related to Pydantic V1.X

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0