Chromium Code Reviews| Index: pkg/http_server/lib/src/virtual_directory.dart |
| diff --git a/pkg/http_server/lib/src/virtual_directory.dart b/pkg/http_server/lib/src/virtual_directory.dart |
| index 680781e1c501eef310b210944639686fd49e596f..80b84b839fec321a2f2231d3dd654b5876e41555 100644 |
| --- a/pkg/http_server/lib/src/virtual_directory.dart |
| +++ b/pkg/http_server/lib/src/virtual_directory.dart |
| @@ -55,8 +55,8 @@ abstract class VirtualDirectory { |
| class _VirtualDirectory implements VirtualDirectory { |
| final String root; |
| - bool _allowDirectoryListing = false; |
| - bool _followLinks = true; |
| + bool allowDirectoryListing = false; |
| + bool followLinks = true; |
| _VirtualDirectory(this.root); |
| @@ -71,7 +71,7 @@ class _VirtualDirectory implements VirtualDirectory { |
| return _serveErrorPage(HttpStatus.NOT_FOUND, request); |
| } |
| - _locateResource(new Path(root), path.segments()) |
| + _locateResource(new Path('.'), path.segments()) |
| .then((entity) { |
| if (entity == null) { |
| _serveErrorPage(HttpStatus.NOT_FOUND, request); |
| @@ -87,16 +87,19 @@ class _VirtualDirectory implements VirtualDirectory { |
| Future<FileSystemEntity> _locateResource(Path path, |
| Iterable<String> segments) { |
| - return FileSystemEntity.type(path.toNativePath(), followLinks: false) |
| + Path fullPath() => new Path(root).join(path); |
| + return FileSystemEntity.type(fullPath().toNativePath(), followLinks: false) |
| .then((type) { |
| switch (type) { |
| case FileSystemEntityType.FILE: |
| - if (segments.isEmpty) return new File.fromPath(path); |
| + if (segments.isEmpty) return new File.fromPath(fullPath()); |
| break; |
| case FileSystemEntityType.DIRECTORY: |
| if (segments.isEmpty) { |
| - if (_allowDirectoryListing) return new Directory.fromPath(path); |
| + if (allowDirectoryListing) { |
| + return new Directory.fromPath(fullPath()); |
| + } |
| } else { |
| return _locateResource(path.append(segments.first), |
| segments.skip(1)); |
| @@ -105,7 +108,17 @@ class _VirtualDirectory implements VirtualDirectory { |
| case FileSystemEntityType.LINK: |
| if (followLinks) { |
| - // TODO |
| + return new Link.fromPath(fullPath()).target() |
| + .then((target) { |
| + var targetPath = new Path(target).canonicalize(); |
| + if (targetPath.isAbsolute) return null; |
| + targetPath = path.append('..').join(targetPath) |
|
Søren Gjesse
2013/06/24 08:08:53
Why do you need this additional ..?
Anders Johnsen
2013/06/24 08:21:16
To 'pop' the link. Changed to use path.directoryPa
|
| + .canonicalize(); |
| + if (targetPath.segments().isEmpty || |
| + targetPath.segments().first == '..') return null; |
| + return _locateResource(targetPath.append(segments.first), |
| + segments.skip(1)); |
| + }); |
| } |
| break; |
| } |