Validte that lookup arrays are actually arrays

This commit is contained in:
MarkBaker 2022-03-16 21:30:19 +01:00
parent 4c1d953897
commit 4881e2ae9e
4 changed files with 20 additions and 1 deletions

View File

@ -32,9 +32,10 @@ class HLookup extends LookupBase
}
$notExactMatch = (bool) ($notExactMatch ?? true);
$lookupArray = self::convertLiteralArray($lookupArray);
try {
self::validateLookupArray($lookupArray);
$lookupArray = self::convertLiteralArray($lookupArray);
$indexNumber = self::validateIndexLookup($lookupArray, $indexNumber);
} catch (Exception $e) {
return $e->getMessage();

View File

@ -7,6 +7,16 @@ use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
abstract class LookupBase
{
/**
* @param mixed $lookup_array
*/
protected static function validateLookupArray($lookup_array): void
{
if (!is_array($lookup_array)) {
throw new Exception(ExcelError::REF());
}
}
protected static function validateIndexLookup(array $lookup_array, $index_number): int
{
// index_number must be a number greater than or equal to 1

View File

@ -33,6 +33,7 @@ class VLookup extends LookupBase
$notExactMatch = (bool) ($notExactMatch ?? true);
try {
self::validateLookupArray($lookupArray);
$indexNumber = self::validateIndexLookup($lookupArray, $indexNumber);
} catch (Exception $e) {
return $e->getMessage();

View File

@ -24,6 +24,13 @@ return [
2,
false,
],
[
'#REF!',
1,
'HELLO WORLD',
2,
false,
],
[
100,
1,