Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[feature] add non-exhausive URI validation #352

Closed
yozachar opened this issue Apr 2, 2024 · 10 comments · Fixed by #353
Closed

[feature] add non-exhausive URI validation #352

yozachar opened this issue Apr 2, 2024 · 10 comments · Fixed by #353
Labels
enhancement Issue/PR: A new feature

Comments

@yozachar
Copy link
Collaborator

yozachar commented Apr 2, 2024


Suggestions are welcome:

@validator
def uri(value: str, /):
"""Return whether or not given value is a valid URI.
Examples:
>>> uri('mailto:example@domain.com')
# Output: True
>>> uri('file:path.txt')
# Output: ValidationError(func=uri, ...)
Args:
value:
URI to validate.
Returns:
(Literal[True]): If `value` is a valid URI.
(ValidationError): If `value` is an invalid URI.
"""

@yozachar yozachar added the enhancement Issue/PR: A new feature label Apr 2, 2024
@yozachar yozachar linked a pull request Apr 3, 2024 that will close this issue
@yozachar yozachar pinned this issue Apr 9, 2024
@tofetpuzo
Copy link

are you taking any new suggestions?

@yozachar
Copy link
Collaborator Author

Constructive ones, please go ahead.

@tofetpuzo
Copy link

tofetpuzo commented Jun 24, 2024

--- # Define a list of valid URI schemes => VALID_SCHEMES = ['http', 'https', 'ftp', 'mailto', 'file']

  1. We could make the parameter-> value(str) flexible perhaps not restrict it to a type str, could be src/path/to/file; which could contain different urls
  2. do a recursive search(regex expression perhaps) to match pattern

@tofetpuzo
Copy link

is it something we should do?

@yozachar
Copy link
Collaborator Author

Something similar yeah.

@tofetpuzo
Copy link

can I take up the challenge :)?

@yozachar
Copy link
Collaborator Author

yozachar commented Jul 4, 2024

Sure, go ahead.

@tofetpuzo
Copy link

tofetpuzo commented Jul 9, 2024

Hey @yozachar ,can we use socket.inet_aton(ip) in python to validate ip addresses as a function then update the schema in uri.py?

   # URL-based schemes
    if any(
        value.startswith(item + "://") for item in {
            "ftp", "ftps", "git", "http", "https",
            "irc", "rtmp", "rtmps", "rtsp", "sftp",
            "ssh", "telnet", "gopher", "ldap", "sip",
            "nfs", "mqtt", "smb", "udp"
        }
    ):

@yozachar
Copy link
Collaborator Author

yozachar commented Jul 10, 2024

IP addresses are already validated in ip_address.py. Why use socket.inet_aton?

@tofetpuzo
Copy link

tofetpuzo commented Jul 10, 2024

Hi, that is cool I looked at the message thread, something about this error below , was why I thought this feature was asked for I guess, see code below.

import validators

streamurl = "rtmp://192.168.1.123:1935/live/test"
print(validators.url(streamurl))

Output:
ValidationError(func=url, args={'value': 'rtmp://192.168.1.123:1935/live/test'})

Or does it mean we just want to validate other schemas? like the ones few ones below, that I could not find in uri.py

proposed schemas

"Uri":  {
"udp": udp://192.168.1.1:1234/path;param=value?,

"gopher": gopher://gopher.example.com/1/path;type=1?search#frag,\
"ldap": ldap://ldap.example.com/cn=John%20Doe,dc=example,dc=com;scope=one?sn#frag, \
"sip":sip://user:password@sip.example.com/path;transport=tcp?subject=Hello#frag, \
"smb": smb://fileserver.example.com/share/path;param=value?query=1#fragment\
 }

Few Thoughts

  1. Have a regex expression : that complies the schema above.
  2. uri_regrex: re.compile()
    e.g
  # Validate using regex for URL-based schemes
    if uri_regex.match(value):
        return True

@python-validators python-validators locked and limited conversation to collaborators Jul 10, 2024
@yozachar yozachar converted this issue into discussion #388 Jul 10, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
enhancement Issue/PR: A new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants