rfc3986 icon indicating copy to clipboard operation
rfc3986 copied to clipboard

Resolution result is not consistent with RFC 3986 when the base has "rootless" path without authority

Open lo48576 opened this issue 3 years ago • 0 comments

remove_dot_segments defined in RFC 3986 (section 5.2.4) sometimes add a leading slash when the base path is "rootless".

STEP   OUTPUT BUFFER         INPUT BUFFER

 1 :                         foo/../baz
 2E:   foo                   /../baz
 2C:                         /baz
 2E:   /baz

So, resolving ../baz against scheme:foo/bar should result in scheme:/baz. However, output of this library differs from that.

$ python
Python 3.9.9 (main, Jan 10 2022, 18:52:39)
[GCC 11.2.1 20211127] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from rfc3986 import uri_reference
>>> b = uri_reference('scheme:foo/bar')
>>> r = uri_reference('../baz')
>>> t = r.resolve_with(b)
>>> t
URIReference(scheme='scheme', authority=None, path='baz', query=None, fragment=None)
>>> t.unsplit()
'scheme:baz'
>>>

I think there should be special handling such as "when .. segment appears but output stack is empty, set prepend_slash flag" or something like that.

lo48576 avatar Jan 10 '22 12:01 lo48576