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

Unified Diff: pkg/http_server/lib/src/virtual_directory.dart

Issue 18333003: Correctly url-decode the path segment in the http_server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add another test. Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
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 bb3b7ac44260916aae1e135a5e7a027441814651..a06a8d57dc713b5da3b25d5d9a5f960f30e9f803 100644
--- a/pkg/http_server/lib/src/virtual_directory.dart
+++ b/pkg/http_server/lib/src/virtual_directory.dart
@@ -75,13 +75,7 @@ class _VirtualDirectory implements VirtualDirectory {
}
void serveRequest(HttpRequest request) {
- var path = new Path(request.uri.path).canonicalize();
-
- if (!path.isAbsolute) {
- return _serveErrorPage(HttpStatus.NOT_FOUND, request);
- }
-
- _locateResource(new Path('.'), path.segments())
+ _locateResource(new Path('.'), request.uri.pathSegments)
.then((entity) {
if (entity == null) {
_serveErrorPage(HttpStatus.NOT_FOUND, request);
@@ -107,6 +101,8 @@ class _VirtualDirectory implements VirtualDirectory {
Future<FileSystemEntity> _locateResource(Path path,
Iterable<String> segments) {
+ path = path.canonicalize();
Lasse Reichstein Nielsen 2013/07/02 07:31:14 So you canonicalize after each segment is added. W
Anders Johnsen 2013/07/02 11:08:07 Yes, that's the idea.
+ if (path.segments().first == "..") return new Future.value(null);
Path fullPath() => new Path(root).join(path);
return FileSystemEntity.type(fullPath().toNativePath(), followLinks: false)
.then((type) {
@@ -132,15 +128,8 @@ class _VirtualDirectory implements VirtualDirectory {
.then((target) {
var targetPath = new Path(target).canonicalize();
if (targetPath.isAbsolute) return null;
- targetPath =
- path.directoryPath.join(targetPath).canonicalize();
- if (targetPath.segments().isEmpty ||
- targetPath.segments().first == '..') return null;
- if (segments.isEmpty) {
- return _locateResource(targetPath, []);
- }
- return _locateResource(targetPath.append(segments.first),
- segments.skip(1));
+ targetPath = path.directoryPath.join(targetPath);
+ return _locateResource(targetPath, segments);
});
}
break;
« no previous file with comments | « no previous file | pkg/http_server/test/virtual_directory_test.dart » ('j') | pkg/http_server/test/virtual_directory_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698