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

Side by Side Diff: utils/pub/io.dart

Issue 11528020: Fix issue 7215 by relativising a path before checking its components. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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 | « utils/pub/command_lish.dart ('k') | no next file » | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /** 5 /**
6 * Helper functionality to make working with IO easier. 6 * Helper functionality to make working with IO easier.
7 */ 7 */
8 library io; 8 library io;
9 9
10 import 'dart:io'; 10 import 'dart:io';
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 } 67 }
68 68
69 // TODO(nweiz): move this into path.dart. 69 // TODO(nweiz): move this into path.dart.
70 /// Splits [path] into its individual components. 70 /// Splits [path] into its individual components.
71 List<String> splitPath(path) => _sanitizePath(path).split('/'); 71 List<String> splitPath(path) => _sanitizePath(path).split('/');
72 72
73 /// Returns whether or not [entry] is nested somewhere within [dir]. This just 73 /// Returns whether or not [entry] is nested somewhere within [dir]. This just
74 /// performs a path comparison; it doesn't look at the actual filesystem. 74 /// performs a path comparison; it doesn't look at the actual filesystem.
75 bool isBeneath(entry, dir) { 75 bool isBeneath(entry, dir) {
76 var relative = relativeTo(entry, dir); 76 var relative = relativeTo(entry, dir);
77 return !path.isAbsolute(relative) && !relative.startsWith('..'); 77 return !path.isAbsolute(relative) && splitPath(relative)[0] != '..';
78 } 78 }
79 79
80 // TODO(nweiz): move this into path.dart. 80 // TODO(nweiz): move this into path.dart.
81 /// Returns the path to [target] from [base]. 81 /// Returns the path to [target] from [base].
82 String relativeTo(target, base) => 82 String relativeTo(target, base) =>
83 new path.Builder(root: base).relative(target); 83 new path.Builder(root: base).relative(target);
84 84
85 /** 85 /**
86 * Asynchronously determines if [path], which can be a [String] file path, a 86 * Asynchronously determines if [path], which can be a [String] file path, a
87 * [File], or a [Directory] exists on the file system. Returns a [Future] that 87 * [File], or a [Directory] exists on the file system. Returns a [Future] that
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 return new Directory(entry); 1110 return new Directory(entry);
1111 } 1111 }
1112 1112
1113 /** 1113 /**
1114 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. 1114 * Gets a [Uri] for [uri], which can either already be one, or be a [String].
1115 */ 1115 */
1116 Uri _getUri(uri) { 1116 Uri _getUri(uri) {
1117 if (uri is Uri) return uri; 1117 if (uri is Uri) return uri;
1118 return new Uri.fromString(uri); 1118 return new Uri.fromString(uri);
1119 } 1119 }
OLDNEW
« no previous file with comments | « utils/pub/command_lish.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698