Page MenuHomePhabricator

D14418.id.diff
No OneTemporary

D14418.id.diff

diff --git a/src/filesystem/Filesystem.php b/src/filesystem/Filesystem.php
--- a/src/filesystem/Filesystem.php
+++ b/src/filesystem/Filesystem.php
@@ -871,14 +871,13 @@
* @task path
*/
public static function isDescendant($path, $root) {
- try {
- self::assertExists($path);
- self::assertExists($root);
- } catch (FilesystemException $e) {
- return false;
- }
- $fs = new FileList(array($root));
- return $fs->contains($path);
+ $path = self::resolvePath($path);
+ $root = self::resolvePath($root);
+
+ $relative_path = self::relativePath($root, $path);
+
+ $parts = explode('/', $relative_path);
+ return head($parts) != '..';
}
/**
diff --git a/src/filesystem/__tests__/FilesystemTestCase.php b/src/filesystem/__tests__/FilesystemTestCase.php
--- a/src/filesystem/__tests__/FilesystemTestCase.php
+++ b/src/filesystem/__tests__/FilesystemTestCase.php
@@ -136,28 +136,45 @@
public function testisDescendant() {
$test_cases = array(
array(
- __FILE__,
- dirname(__FILE__),
+ '/foo/bar/baz',
+ '/',
true,
),
array(
- dirname(__FILE__),
- dirname(dirname(__FILE__)),
+ '/foo/bar/baz',
+ '/foo',
true,
),
array(
- dirname(__FILE__),
- phutil_get_library_root_for_path(__FILE__),
+ '/foo/bar/baz',
+ '/foo/bar/baz',
true,
),
array(
- dirname(dirname(__FILE__)),
- dirname(__FILE__),
+ '/foo/foobar',
+ '/foo/bar/baz',
false,
),
array(
- dirname(__FILE__).'/quack',
- dirname(__FILE__),
+ '/',
+ '/foo/bar/baz',
+ false,
+ ),
+ array(
+ 'some/path',
+ 'src/',
+ false,
+ ),
+
+ // Windows paths
+ array(
+ 'c:\\Windows\\System32\\Drivers\\etc\\hosts',
+ 'c:\\',
+ true,
+ ),
+ array(
+ 'c:\\Windows\\System32\\Drivers\\etc\\hosts',
+ 'c:\\Users\\Bill Gates\\',
false,
),
);

File Metadata

Mime Type
text/plain
Expires
Thu, Oct 31, 2:39 PM (4 d, 7 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6731844
Default Alt Text
D14418.id.diff (2 KB)

Event Timeline