Description
Dart SDK version: 3.9.0-63.0.dev (dev) (Sun Apr 27 17:07:04 2025 -0700) on "macos_x64"
This is a discussion to determine if additional API would be beneficial and not a request to change current behaviour of current API since it is not a matter of correctness, so such changes would be non-necessarily breaking.
Current dart:io
and dart:core
API
The default behaviour which is documented for file system objects of dart:io
and the URI API of dart:core
is to treat relative paths as its own thing and not a URI with a scheme. For example
print(Uri.file('.').hasScheme);
outputs
false
and
print(Directory('.').uri.scheme);
outputs nothing because there is no scheme.
Relative File URIs
RFC 3986
defines the URI grammar as
The generic URI syntax consists of a hierarchical sequence of components referred to as the scheme, authority, path, query, and fragment. URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] hier-part = "//" authority path-abempty / path-absolute / path-rootless / path-empty
Applying grammar productions using path-rootless
, it is possible to derive File URIs of the form
"file:" path-rootless [ "?" query ] [ "#" fragment ]
Which is relative paths, optionally with queries and fragments eg file:Documentation/readme.md#getting-started
.
RFC 3986
Compliance
The Dart behaviour deviates from RFC 3986
, which is fine as its behaviour is documented and still practical. Since RFC 3986
is a widely adopted specification, should additional API be introduced that conforms to it as expected. Something like
Directory.rfc('.')
will have a URI file:.
and
Uri.fileRfc('.')
will also have URI file:.
.
This would also mean, for this new API,?
can be treated as a query declaration and #
can be treated as the fragment declaration.