diff options
author | Cameron Porter <camporter1@gmail.com> | 2021-02-14 22:55:25 -0600 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2021-02-23 09:50:36 +0100 |
commit | 24e7299c9d7b9d41a50da591b9230c87deafcf4e (patch) | |
tree | 039fc344b5936d7d868d4b2678386012ad602443 /ext | |
parent | da011a312a6c6cd7ff12fe1aa0de1e33fba2f167 (diff) | |
download | php-git-24e7299c9d7b9d41a50da591b9230c87deafcf4e.tar.gz |
Fixed bug #80724
FilesystemIterator::FOLLOW_SYMLINKS is currently treated as a directory
key mode flag, even though it does not change the way that the key
during iteration is set. To address this, FOLLOW_SYMLINKS has been
converted into an OTHER flag.
Closes GH-6695.
Diffstat (limited to 'ext')
-rw-r--r-- | ext/spl/spl_directory.h | 4 | ||||
-rw-r--r-- | ext/spl/tests/RecursiveDirectoryIterator_hasChildren.phpt | 35 | ||||
-rw-r--r-- | ext/spl/tests/bug80724.phpt | 46 | ||||
-rw-r--r-- | ext/spl/tests/filesystemiterator_flags.phpt | 4 |
4 files changed, 85 insertions, 4 deletions
diff --git a/ext/spl/spl_directory.h b/ext/spl/spl_directory.h index 88fbd0f052..e3deb81aeb 100644 --- a/ext/spl/spl_directory.h +++ b/ext/spl/spl_directory.h @@ -136,12 +136,12 @@ static inline spl_filesystem_object* spl_filesystem_iterator_to_object(spl_files #define SPL_FILE_DIR_KEY_AS_PATHNAME 0x00000000 /* make RecursiveDirectoryTree::key() return getPathname() */ #define SPL_FILE_DIR_KEY_AS_FILENAME 0x00000100 /* make RecursiveDirectoryTree::key() return getFilename() */ -#define SPL_FILE_DIR_FOLLOW_SYMLINKS 0x00000200 /* make RecursiveDirectoryTree::hasChildren() follow symlinks */ #define SPL_FILE_DIR_KEY_MODE_MASK 0x00000F00 /* mask RecursiveDirectoryTree::key() */ #define SPL_FILE_DIR_KEY(intern,mode) ((intern->flags&SPL_FILE_DIR_KEY_MODE_MASK)==mode) #define SPL_FILE_DIR_SKIPDOTS 0x00001000 /* Tells whether it should skip dots or not */ #define SPL_FILE_DIR_UNIXPATHS 0x00002000 /* Whether to unixify path separators */ -#define SPL_FILE_DIR_OTHERS_MASK 0x00003000 /* mask used for get/setFlags */ +#define SPL_FILE_DIR_FOLLOW_SYMLINKS 0x00004000 /* make RecursiveDirectoryTree::hasChildren() follow symlinks */ +#define SPL_FILE_DIR_OTHERS_MASK 0x00007000 /* mask used for get/setFlags */ #endif /* SPL_DIRECTORY_H */ diff --git a/ext/spl/tests/RecursiveDirectoryIterator_hasChildren.phpt b/ext/spl/tests/RecursiveDirectoryIterator_hasChildren.phpt new file mode 100644 index 0000000000..a4bad9b52d --- /dev/null +++ b/ext/spl/tests/RecursiveDirectoryIterator_hasChildren.phpt @@ -0,0 +1,35 @@ +--TEST-- +SPL: RecursiveDirectoryIterator::hasChildren() follow symlinks test +--FILE-- +<?php + +$dir = __DIR__ . DIRECTORY_SEPARATOR . 'symlinktest'; + +if (!mkdir($dir)) { + die('Failed to create temporary directory for testing'); +} elseif (!symlink(__DIR__, $dir . DIRECTORY_SEPARATOR . 'symlink')) { + die('Failed to create symbolic link'); +} + +$it = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS | FilesystemIterator::FOLLOW_SYMLINKS | FilesystemIterator::KEY_AS_FILENAME); + +var_dump($it->key()); +var_dump($it->hasChildren()); + +$it->setFlags(FilesystemIterator::SKIP_DOTS | FilesystemIterator::KEY_AS_FILENAME); + +var_dump($it->key()); +var_dump($it->hasChildren()); + +?> +--EXPECT-- +string(7) "symlink" +bool(true) +string(7) "symlink" +bool(false) +--CLEAN-- +<?php +$dir = __DIR__ . DIRECTORY_SEPARATOR . 'symlinktest'; +unlink($dir . DIRECTORY_SEPARATOR . 'symlink'); +rmdir($dir); +?> diff --git a/ext/spl/tests/bug80724.phpt b/ext/spl/tests/bug80724.phpt new file mode 100644 index 0000000000..7ff118e31b --- /dev/null +++ b/ext/spl/tests/bug80724.phpt @@ -0,0 +1,46 @@ +--TEST-- +Bug #80724 (FOLLOW_SYMLINKS interfering with FilesystemIterator key flags) +--FILE-- +<?php +$iterator = new FilesystemIterator(__DIR__, FilesystemIterator::KEY_AS_FILENAME); +foreach ($iterator as $key => $value) { + echo var_dump(hasSeparator($key)); + break; +} +$iterator->rewind(); +echo var_dump(hasSeparator($iterator->key())); + +$iterator->setFlags(0); +echo var_dump(hasSeparator($iterator->key())); + +$iterator->setFlags(FilesystemIterator::KEY_AS_FILENAME); +echo var_dump(hasSeparator($iterator->key())); + +$iterator2 = new FilesystemIterator(__DIR__, FilesystemIterator::FOLLOW_SYMLINKS | FilesystemIterator::KEY_AS_FILENAME); +foreach ($iterator2 as $key => $value) { + echo var_dump(hasSeparator($key)); + break; +} +$iterator2->rewind(); +echo var_dump(hasSeparator($iterator2->key())); + +$iterator2->setFlags(0); +echo var_dump(hasSeparator($iterator2->key())); + +$iterator2->setFlags(FilesystemIterator::KEY_AS_FILENAME); +echo var_dump(hasSeparator($iterator2->key())); + +function hasSeparator($key) { + return str_contains($key, __DIR__ . DIRECTORY_SEPARATOR); +} + +?> +--EXPECT-- +bool(false) +bool(false) +bool(true) +bool(false) +bool(false) +bool(false) +bool(true) +bool(false) diff --git a/ext/spl/tests/filesystemiterator_flags.phpt b/ext/spl/tests/filesystemiterator_flags.phpt index 1a8cce034e..b4e582b77a 100644 --- a/ext/spl/tests/filesystemiterator_flags.phpt +++ b/ext/spl/tests/filesystemiterator_flags.phpt @@ -34,7 +34,7 @@ function printflags($it) { 00000010 00000100 00003000 -00003FF0 +00007FF0 000000F0 00000F00 -00003000 +00007000 |