yescallop / fluent-uri-rs

A generic URI/IRI handling library compliant with RFC 3986/3987.
MIT License
80 stars 6 forks source link

Scheme-based normalization #27

Open Stranger6667 opened 3 weeks ago

Stranger6667 commented 3 weeks ago

As far as I see, fluent_uri==0.3.0 normalizes http://example.com and http://example.com:80 to different values and therefore does not consider them equal. My reading of RFC 3986 6.2.3 is that such URIs should be considered equivalent.

For example, because the "http" scheme makes use of an authority component, has a default port of "80", and defines an empty path to be equivalent to "/", the following four URIs are equivalent: http://example.com http://example.com/ http://example.com:/ http://example.com:80/

Is my understanding correct? If so, would it make sense to adjust the normalization logic in fluent_uri so it matches this semantics?

yescallop commented 1 week ago

I think it would be nice to have a minimal implementation of scheme-based normalization in this library. Would you define the scope of your use case, such as which schemes you need this behavior with, and is it just default port normalization that you need, or do you also need to normalize an empty path to / for HTTP, for example?

Stranger6667 commented 1 week ago

In my use case, I needed o follow the json schema reference resolution rules that require normalisation. There is a test suite for this behaviour and right now, only default port normalisation tests are failing

https://github.com/python-jsonschema/referencing-suite/blob/main/tests/json-schema-draft-2020-12/rfc3986-normalization-on-retrieval.json

Other than that, the current normalisation fits my needs perfectly! :)