Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new Uri.directory #17065

Closed
peter-ahe-google opened this issue Feb 24, 2014 · 3 comments
Closed

new Uri.directory #17065

peter-ahe-google opened this issue Feb 24, 2014 · 3 comments
Labels
area-library library-core type-enhancement A request for a change that isn't a bug

Comments

@peter-ahe-google
Copy link
Contributor

Converting a native directory path to a URI is error prone. The method Uri.resolve will strip the last path segment, and if one is aware of this and takes care to always append slashes to URIs representing a directory, Uri.resolve is rather powerful:

Convert relative file name [path] to absolute file name:

Uri.base.resolve(new Uri.file(path))

Get the directory name of file name [path]:

new Uri.file(path).resolve('.')

Get the parent directory of file name [path]:

new Uri.file(path).resolve('..')

However, if one has a native path to a directory, the above doesn't work if [path] doesn't end with the native path separator. So one must take care to append a slash. The simplest way I have found, without importing Platform from dart:io is:

Uri nativeDirectoryToUri(String nativePath) {
  Uri uri = new Uri.file(nativePath);
  String path = uri.path;
  return (path == '' || path.endsWith('/'))
      ? uri
      : Uri.parse('$uri/');
}

I propose this gets added to the Uri class, for example, as a factory analogous to Uri.file.

@DartBot
Copy link

DartBot commented Feb 24, 2014

This comment was originally written by whesse@chromium.org


I strongly agree with adding a constructor Uri.directory, similar to Uri.file, except that it guarantees that the path of the Uri ends in /, unless the path is the empty string.

This is the largest pain point we have found in using file: URIs to handle paths everywhere.

@kevmoo
Copy link
Member

kevmoo commented Apr 26, 2014

Removed Type-Defect label.
Added Type-Enhancement label.

@lrhn
Copy link
Member

lrhn commented Apr 17, 2015

I've added Uri.directory constructor similar to Uri.file, but guaranteeing that a non-empty path ends with "/".


Added Fixed label.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-library library-core type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants