guri: Fix paths starting with ‘//’ when parsing
This fixes cases where calling g_uri_to_string()
immediately after a
successful call to g_uri_parse()
would cause an assertion failure for
URIs like data:/.//
or data:.///
.
These appear to be valid URIs. Their paths are normalised to //
during
parsing as a result of the remove_dot_segments()
algorithm. This then
falls foul of the restriction from
https://datatracker.ietf.org/doc/html/rfc3986#section-3 that
When authority is not present, the path cannot begin with two slash characters ("//").
This is already encoded in an assertion at the top of
g_uri_join_internal()
.
The approach of prefixing the path with /.
should be harmless: it
guarantees the path starts with /
, prevents //
being a prefix, and
should always be removed by remove_dot_segments()
when re-parsing the
URI. It’s the same approach as taken in the WhatWG URL spec for a
similar (but different) situation:
https://url.spec.whatwg.org/#url-serializing (see step 3).
See also: libsoup!415 (79cfd65c)
Signed-off-by: Philip Withnall pwithnall@gnome.org