GithubHelp home page GithubHelp logo

Comments (10)

sethmlarson avatar sethmlarson commented on June 27, 2024 5

Or just remove it, it's been deprecated for a few releases.

from rfc3986.

bugeats avatar bugeats commented on June 27, 2024 1
rfc3986.is_valid_uri("Hi Super Nintendo Chalmers") # -> True
rfc3986.is_valid_uri("My cat's breath smells like cat food.") # -> True
rfc3986.is_valid_uri("I'm learnding!") # -> True

Something is deeply wrong here.

from rfc3986.

sethmlarson avatar sethmlarson commented on June 27, 2024

Really this method should be is_valid_uri_reference(), but each of these are valid URI references.

# A no-scheme path with zero extra segments
>>> rfc3986.uri_reference('1')
URIReference(scheme=None, authority=None, path='1', query=None, fragment=None)

# A relative-ref with an empty path and no scheme.
>>> rfc3986.uri_reference('//')
URIReference(scheme=None, authority=None, path=None, query=None, fragment=None)

# A relative-ref with a non-empty path and a fragment.
>>> rfc3986.uri_reference('http#:/')
URIReference(scheme=None, authority=None, path='http', query=None, fragment=':/')

from rfc3986.

sigmavirus24 avatar sigmavirus24 commented on June 27, 2024

Right. There's a far better and more comprehensive way of doing validations

from rfc3986.

sigmavirus24 avatar sigmavirus24 commented on June 27, 2024

https://rfc3986.readthedocs.io/en/latest/user/validating.html

from rfc3986.

sethmlarson avatar sethmlarson commented on June 27, 2024

@bugeats All of those examples pass the validation check because URIReference.from_string() does normalization which converts characters within components that can be percent-encoded into their percent-encoded counterparts before calling is_valid() (Meaning all of that text ends up being a percent encoded path). And because there aren't any kwargs to "require" any component in particular we get a result of True.

Using the Validator interface makes this all more clear.
You can achieve what I believe you want via:

def is_valid_uri_with_scheme_and_host(uri):
    try:
        uri = rfc3986.URIReference.from_string(uri)
        rfc3986.validators.Validator().require_presence_of("scheme", "host").check_validity_of("scheme", "host").validate(uri)
        return True
    except MissingComponentError, InvalidComponentsError:
        return False

Will return False for all your examples but True for https://www.google.com/ and the like.

from rfc3986.

bugeats avatar bugeats commented on June 27, 2024

Yes I eventually figured that out, thanks for the detailed response. I mostly wanted to point out the absurdity of the code as it reads. I humbly suggest that you reconsider the name of that method.

from rfc3986.

hartwork avatar hartwork commented on June 27, 2024

I want to use this library to detect foo bar (with a space) as an invalid URI with regard to RFC 3986. All parts of the API of this library that I have seen so far auto-correct foo bar to foo%20bar for me. How can I disable that behavior and get an exception, instead? What class and functions can I use for strict parsing behavior if is_valid_uri and .is_valid are not strict? Thanks!

from rfc3986.

hartwork avatar hartwork commented on June 27, 2024

Anyone?

from rfc3986.

kenballus avatar kenballus commented on June 27, 2024

Almost a year late to the party here.

If you don't mind using something home-grown, you could try using it.
I went through RFC3986 and converted all the ABNF to regexes.
I left the ABNF in comments above the regexes so you can verify the code for yourself.

from rfc3986.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.