Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ PHP NEWS
. Add enum SortDirection. (timwolla)
. pathinfo() raises a ValueError with an invalid $flags argument.
(David Carlier)
. Passing an invalid flag value to the second argument of scandir() will now
throw a ValueError. (alexandre-daubois)

- Streams:
. Added so_keepalive, tcp_keepidle, tcp_keepintvl and tcp_keepcnt stream
Expand Down
2 changes: 2 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ PHP 8.6 UPGRADE NOTES
- Standard:
. pathinfo() now raises a ValueError when an invalid $flag argument
value is passed.
. scandir() now raises a ValueError when an invalid $sorting_order
argument value is passed.

- Zip:
. ZipArchive::extractTo now raises a TypeError for the
Expand Down
8 changes: 6 additions & 2 deletions ext/standard/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,13 @@ PHP_FUNCTION(scandir)
n = php_stream_scandir(dirn, &namelist, context, (void *) php_stream_dirent_alphasort);
} else if (flags == PHP_SCANDIR_SORT_NONE) {
n = php_stream_scandir(dirn, &namelist, context, NULL);
} else {
} else if (flags == PHP_SCANDIR_SORT_DESCENDING) {
n = php_stream_scandir(dirn, &namelist, context, (void *) php_stream_dirent_alphasortr);
}
} else {
zend_argument_value_error(2, "must be one of the SCANDIR_SORT_ASCENDING, SCANDIR_SORT_DESCENDING, or SCANDIR_SORT_NONE constants");
RETURN_THROWS();
}

if (n < 0) {
php_error_docref(NULL, E_WARNING, "(errno %d): %s", errno, strerror(errno));
RETURN_FALSE;
Expand Down
12 changes: 12 additions & 0 deletions ext/standard/tests/dir/scandir_invalid_flag.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Provide wrong flags to scandir()
--FILE--
<?php
try {
scandir('something', -1);
} catch (ValueError $e) {
echo $e->getMessage() . "\n";
}
?>
--EXPECT--
scandir(): Argument #2 ($sorting_order) must be one of the SCANDIR_SORT_ASCENDING, SCANDIR_SORT_DESCENDING, or SCANDIR_SORT_NONE constants
71 changes: 0 additions & 71 deletions ext/standard/tests/dir/scandir_variation9-win32-mb.phpt

This file was deleted.

65 changes: 0 additions & 65 deletions ext/standard/tests/dir/scandir_variation9.phpt

This file was deleted.

Loading