Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,11 @@ PHP_FUNCTION(pathinfo)
Z_PARAM_LONG(opt)
ZEND_PARSE_PARAMETERS_END();

if (opt < PHP_PATHINFO_DIRNAME || opt > PHP_PATHINFO_ALL) {
zend_argument_value_error(2, "must be one of the PATHINFO_* constants");
RETURN_THROWS();
}

have_basename = (opt & PHP_PATHINFO_BASENAME);

array_init(&tmp);
Expand Down
13 changes: 13 additions & 0 deletions ext/standard/tests/strings/pathinfo.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ var_dump(pathinfo(__FILE__, PATHINFO_FILENAME|PATHINFO_BASENAME));
var_dump(pathinfo(__FILE__, PATHINFO_DIRNAME|PATHINFO_EXTENSION));
var_dump(pathinfo(__FILE__, PATHINFO_DIRNAME|PATHINFO_BASENAME));

try {
pathinfo(__FILE__, PATHINFO_DIRNAME-1);
} catch (\ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}
try {
pathinfo(__FILE__, PATHINFO_ALL+1);
} catch (\ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}

echo "Done\n";
?>
--EXPECTF--
Expand Down Expand Up @@ -102,4 +113,6 @@ string(%d) "%s%estrings"
string(12) "pathinfo.php"
string(%d) "%s%estrings"
string(%d) "%s%estrings"
pathinfo(): Argument #2 ($flags) must be one of the PATHINFO_* constants
pathinfo(): Argument #2 ($flags) must be one of the PATHINFO_* constants
Done
Loading