python-validators / validators

Python Data Validation for Humans™.
MIT License
960 stars 152 forks source link

URL validator fails is dollar sign '$' is used in the query parameters #306

Closed damianr13 closed 10 months ago

damianr13 commented 11 months ago

Bug description

Example url: https://services.odata.org/OData/OData.svc/Products?$skip=2&$top=2&$orderby=Rating

The URL above is taken from the Open Data Protocol documentation page.

If we try to validate it:

validators.url("https://services.odata.org/OData/OData.svc/Products?$skip=2&$top=2&$orderby=Rating")

We get the following output:

ValidationError(func=url, args={'value': 'https://services.odata.org/OData/OData.svc/Products?$skip=2&$top=2&$orderby=Rating'})

If we remove the dollar signs:

https://services.odata.org/OData/OData.svc/Products?skip=2&top=2&orderby=Rating

The output simply shows:

True

Expected behaviour

Allow dolllar sign in URL query.

validators.url("https://services.odata.org/OData/OData.svc/Products?$skip=2&$top=2&$orderby=Rating")

Should return

True
yozachar commented 11 months ago

Hi @damianr13, we've fixed this in #305

~/test via 🐍 v3.11.5 (.venv) took 8s 
$ pip install --force git+https://github.com/python-validators/validators.git@$(git ls-remote https://github.com/python-validators/validators.git | head -1 | awk '{print $1;}')
Collecting git+https://github.com/python-validators/validators.git@15984e89a96ee8e8ceb9c2148cac6896a85cd71e
  Cloning https://github.com/python-validators/validators.git (to revision 15984e89a96ee8e8ceb9c2148cac6896a85cd71e) to /tmp/pip-req-build-r1m8t211
  Running command git clone --filter=blob:none --quiet https://github.com/python-validators/validators.git /tmp/pip-req-build-r1m8t211
  Running command git rev-parse -q --verify 'sha^15984e89a96ee8e8ceb9c2148cac6896a85cd71e'
  Running command git fetch -q https://github.com/python-validators/validators.git 15984e89a96ee8e8ceb9c2148cac6896a85cd71e
  Resolved https://github.com/python-validators/validators.git to commit 15984e89a96ee8e8ceb9c2148cac6896a85cd71e
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: validators
  Building wheel for validators (pyproject.toml) ... done
  Created wheel for validators: filename=validators-0.22.0-py3-none-any.whl size=26095 sha256=aa9eb59aa67fc5d06e7e3095b57b861af595b6e9ddcc4993a5bbd5b0226b5d66
  Stored in directory: /home/us-er/.cache/pip/wheels/ab/5a/e4/9fba9af05948fb3222e3f888b2d904f8428bc0cc03dbd260ec
Successfully built validators
Installing collected packages: validators
  Attempting uninstall: validators
    Found existing installation: validators 0.22.0
    Uninstalling validators-0.22.0:
      Successfully uninstalled validators-0.22.0
Successfully installed validators-0.22.0

~/test via 🐍 v3.11.5 (.venv) took 11s 
$ python                                
Python 3.11.5 (main, Sep  2 2023, 14:16:33) [GCC 13.2.1 20230801] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import validators
>>> validators.url("https://services.odata.org/OData/OData.svc/Products?$skip=2&$top=2&$orderby=Rating")
True

Also ref: https://python-validators.github.io/validators/reference/url/ (strict_query parameter)