GithubHelp home page GithubHelp logo

Host ']' about rfc3986 HOT 6 OPEN

python-hyper avatar python-hyper commented on June 27, 2024
Host ']'

from rfc3986.

Comments (6)

kenballus avatar kenballus commented on June 27, 2024

Also a problem when host is '['

from rfc3986.

sigmavirus24 avatar sigmavirus24 commented on June 27, 2024

Happy to accept a fix here

from rfc3986.

frenzymadness avatar frenzymadness commented on June 27, 2024

The question here is whether the validation should or should not be implicit when using uri_reference. The truth is that it parses the URI and returns an invalid result by default:

In [1]: from rfc3986 import uri_reference

In [2]: uri_reference("B://]")
Out[2]: URIReference(scheme='B', authority=']', path=None, query=None, fragment=None)

But you can simply check the validity of the result by the is_valid() method:

In [3]: _.is_valid()
Out[3]: False

If you want the validation to happen immediately during parsing, you can use ParseResult:

In [4]: from rfc3986 import ParseResult

In [5]: ParseResult.from_string("B://]")
…
InvalidAuthority: The authority (]) is not valid.

So, because the lib is already able to say that the URL is invalid, it's more a design decision if the validation should happen by default.

from rfc3986.

sigmavirus24 avatar sigmavirus24 commented on June 27, 2024

Pretty sure uri_reference was always intended to be non-validating so that the rest could be API compatible with urllib3 more or less.

Maybe we need to make that clearer in the docs

from rfc3986.

frenzymadness avatar frenzymadness commented on June 27, 2024

@kenballus could you please clarify which approach did you use?

from rfc3986.

kenballus avatar kenballus commented on June 27, 2024

My mistake; using ParseResult.from_string fixes this. I should have read the docs more thoroughly.

Why is it that we have a non-validating parser? Some large projects (httpx) use this parser, and would probably be better off using ParseResult.from_string.

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.