mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Phar offset exist issue with entry classes not based on PharFileInfo (#14503)
* ext/phar: expand test to cover issue with offsetGet * ext/phar: offsetExists should return false when file entry is not based on PharFileInfo
This commit is contained in:
parent
6a07400699
commit
01c6b48e31
2 changed files with 28 additions and 2 deletions
|
@ -3529,6 +3529,10 @@ PHP_METHOD(Phar, offsetExists)
|
|||
}
|
||||
RETURN_TRUE;
|
||||
} else {
|
||||
/* If the info class is not based on PharFileInfo, directories are not directly instantiable */
|
||||
if (UNEXPECTED(!instanceof_function(phar_obj->spl.info_class, phar_ce_entry))) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETURN_BOOL(zend_hash_exists(&phar_obj->archive->virtual_dirs, file_name));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,10 +13,22 @@ $pharconfig = 0;
|
|||
require_once 'files/phar_oo_test.inc';
|
||||
|
||||
$phar = new Phar($fname);
|
||||
$phar->setInfoClass('SplFileObject');
|
||||
|
||||
$phar['hi/f.php'] = 'hi';
|
||||
var_dump(isset($phar['hi']));
|
||||
var_dump($phar['hi']);
|
||||
var_dump(isset($phar['hi/f.php']));
|
||||
echo $phar['hi/f.php'];
|
||||
echo "\n";
|
||||
|
||||
$phar->setInfoClass('SplFileObject');
|
||||
$phar['hi/f.php'] = 'hi';
|
||||
var_dump(isset($phar['hi']));
|
||||
try {
|
||||
var_dump($phar['hi']);
|
||||
} catch (Throwable $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
|
||||
}
|
||||
var_dump(isset($phar['hi/f.php']));
|
||||
echo $phar['hi/f.php'];
|
||||
echo "\n";
|
||||
|
@ -27,7 +39,17 @@ echo "\n";
|
|||
unlink(__DIR__ . '/files/phar_oo_011.phar.php');
|
||||
__halt_compiler();
|
||||
?>
|
||||
--EXPECT--
|
||||
--EXPECTF--
|
||||
bool(true)
|
||||
object(PharFileInfo)#%d (2) {
|
||||
["pathName":"SplFileInfo":private]=>
|
||||
string(%d) "phar://%s/phar_oo_011.phar.php/hi"
|
||||
["fileName":"SplFileInfo":private]=>
|
||||
string(2) "hi"
|
||||
}
|
||||
bool(true)
|
||||
phar://%s/phar_oo_011.phar.php/hi/f.php
|
||||
bool(false)
|
||||
LogicException: Cannot use SplFileObject with directories
|
||||
bool(true)
|
||||
hi
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue