Skip to content

AnyHttpUrl raises an error if a URL ends with “#” #1807

@ninoseki

Description

@ninoseki

Bug

Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":

            pydantic version: 1.6.1
            pydantic compiled: False
                 install path: /foo/bar/pydantic
               python version: 3.8.2 (default, Apr  8 2020, 09:35:26)  [Clang 11.0.3 (clang-1103.0.32.29)]
                     platform: macOS-10.15.6-x86_64-i386-64bit
     optional deps. installed: ['typing-extensions', 'email-validator', 'devtools']
from pydantic import BaseModel, AnyHttpUrl


class Test(BaseModel):
    url: AnyHttpUrl


test = Test(url="https://example.org#")

It raises the following error.

Traceback (most recent call last):
  File "test.py", line 8, in <module>
    test = Test(url="https://example.org#")
  File "/foo/bar/pydantic/main.py", line 356, in __init__
    raise validation_error
pydantic.error_wrappers.ValidationError: 1 validation error for Test
url
  URL invalid, extra characters found after valid URL: '#' (type=value_error.url.extra; extra=#)

I know this is a very rare case but I found such a URL in the real world.

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