| Index: pkg/pathos/lib/path.dart
|
| diff --git a/pkg/pathos/lib/path.dart b/pkg/pathos/lib/path.dart
|
| index 80ffe72a57da05881db73e521e0753a0788d560b..b9c2936ecc2efb73a8d7188f4330cff5eee79768 100644
|
| --- a/pkg/pathos/lib/path.dart
|
| +++ b/pkg/pathos/lib/path.dart
|
| @@ -203,6 +203,12 @@ String normalize(String path) => _builder.normalize(path);
|
| String relative(String path, {String from}) =>
|
| _builder.relative(path, from: from);
|
|
|
| +/// Returns whether or not [path] is nested somewhere within [dir].
|
| +///
|
| +/// path.isWithin('a/b/c.dart', 'a/b') // -> true
|
| +/// path.isWithin('a/b/c.dart', 'd/b') // -> false
|
| +bool isWithin(String path, String dir) => _builder.isWithin(path, dir);
|
| +
|
| /// Removes a trailing extension from the last part of [path].
|
| ///
|
| /// withoutExtension('path/to/foo.dart'); // -> 'path/to/foo'
|
| @@ -349,7 +355,16 @@ class Builder {
|
| /// On POSIX systems, absolute paths start with a `/` (forward slash). On
|
| /// Windows, an absolute path starts with `\\`, or a drive letter followed by
|
| /// `:/` or `:\`.
|
| - bool isRelative(String path) => !isAbsolute(path);
|
| + bool isRelative(String path) => !this.isAbsolute(path);
|
| +
|
| + /// Returns whether or not [path] is nested somewhere within [dir].
|
| + ///
|
| + /// path.isWithin('a/b/c.dart', 'a/b') // -> true
|
| + /// path.isWithin('a/b/c.dart', 'd/b') // -> false
|
| + bool isWithin(String path, String dir) {
|
| + var relative = this.relative(path, from: dir);
|
| + return !this.isAbsolute(relative) && this.split(relative)[0] != '..';
|
| + }
|
|
|
| /// Joins the given path parts into a single path. Example:
|
| ///
|
|
|