Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1041)

Side by Side Diff: pkg/http_server/lib/src/virtual_directory.dart

Issue 125003002: Fix Directory path in VirtualDirectory, so it always ends with a platform-specific seperator. That'… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/http_server/test/virtual_directory_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of http_server; 5 part of http_server;
6 6
7 /** 7 /**
8 * A [VirtualDirectory] can serve files and directory-listing from a root path, 8 * A [VirtualDirectory] can serve files and directory-listing from a root path,
9 * to [HttpRequest]s. 9 * to [HttpRequest]s.
10 * 10 *
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 _errorCallback = callback; 90 _errorCallback = callback;
91 } 91 }
92 92
93 Future<FileSystemEntity> _locateResource(String path, 93 Future<FileSystemEntity> _locateResource(String path,
94 Iterator<String> segments) { 94 Iterator<String> segments) {
95 // Don't allow navigating up paths. 95 // Don't allow navigating up paths.
96 if (segments.current == "..") return new Future.value(null); 96 if (segments.current == "..") return new Future.value(null);
97 path = normalize(path); 97 path = normalize(path);
98 // If we jail to root, the relative path can never go up. 98 // If we jail to root, the relative path can never go up.
99 if (jailRoot && split(path).first == "..") return new Future.value(null); 99 if (jailRoot && split(path).first == "..") return new Future.value(null);
100 String fullPath() => join(root, path); 100 String fullPath({bool endSlash: false}) {
101 var p = join(root, path);
102 if (endSlash && path != ".") p = "$p$separator";
103 return p;
104 }
101 return FileSystemEntity.type(fullPath(), followLinks: false) 105 return FileSystemEntity.type(fullPath(), followLinks: false)
102 .then((type) { 106 .then((type) {
103 switch (type) { 107 switch (type) {
104 case FileSystemEntityType.FILE: 108 case FileSystemEntityType.FILE:
105 if (segments.current == null) { 109 if (segments.current == null) {
106 return new File(fullPath()); 110 return new File(fullPath());
107 } 111 }
108 break; 112 break;
109 113
110 case FileSystemEntityType.DIRECTORY: 114 case FileSystemEntityType.DIRECTORY:
111 if (segments.current == null) { 115 if (segments.current == null) {
112 if (allowDirectoryListing) { 116 if (allowDirectoryListing) {
113 return new Directory(fullPath()); 117 return new Directory(fullPath(endSlash: true));
114 } 118 }
115 } else { 119 } else {
116 if (_invalidPathRegExp.hasMatch(segments.current)) break; 120 if (_invalidPathRegExp.hasMatch(segments.current)) break;
117 return _locateResource(join(path, segments.current), 121 return _locateResource(join(path, segments.current),
118 segments..moveNext()); 122 segments..moveNext());
119 } 123 }
120 break; 124 break;
121 125
122 case FileSystemEntityType.LINK: 126 case FileSystemEntityType.LINK:
123 if (followLinks) { 127 if (followLinks) {
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 381
378 Future close() => new Future.value(); 382 Future close() => new Future.value();
379 383
380 void setMimeType(var bytes) { 384 void setMimeType(var bytes) {
381 var mimeType = lookupMimeType(path, headerBytes: bytes); 385 var mimeType = lookupMimeType(path, headerBytes: bytes);
382 if (mimeType != null) { 386 if (mimeType != null) {
383 response.headers.contentType = ContentType.parse(mimeType); 387 response.headers.contentType = ContentType.parse(mimeType);
384 } 388 }
385 } 389 }
386 } 390 }
OLDNEW
« no previous file with comments | « no previous file | pkg/http_server/test/virtual_directory_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698