Additional argument validation for LEFT(), MID() and RIGHT() text functions (#1909)

* Additional argument validation for LEFT(), MID() and RIGHT() text functions
This commit is contained in:
Mark Baker 2021-03-08 12:54:06 +01:00 committed by GitHub
parent c4ed0ee7b0
commit f81ffd9a4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 8 deletions

View File

@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
### Fixed
- Fixed issue with Xlsx@listWorksheetInfo not returning any data
- Fixed invalid arguments triggering mb_substr() error in LEFT(), MID() and RIGHT() text functions. [Issue #640](https://github.com/PHPOffice/PhpSpreadsheet/issues/640)
## 1.17.1 - 2021-03-01

View File

@ -299,7 +299,7 @@ class TextData
$value = Functions::flattenSingleValue($value);
$chars = Functions::flattenSingleValue($chars);
if ($chars < 0) {
if (!is_numeric($chars) || $chars < 0) {
return Functions::VALUE();
}
@ -325,7 +325,7 @@ class TextData
$start = Functions::flattenSingleValue($start);
$chars = Functions::flattenSingleValue($chars);
if (($start < 1) || ($chars < 0)) {
if (!is_numeric($start) || $start < 1 || !is_numeric($chars) || $chars < 0) {
return Functions::VALUE();
}
@ -333,10 +333,6 @@ class TextData
$value = ($value) ? Calculation::getTRUE() : Calculation::getFALSE();
}
if (empty($chars)) {
return '';
}
return mb_substr($value, --$start, $chars, 'UTF-8');
}
@ -353,7 +349,7 @@ class TextData
$value = Functions::flattenSingleValue($value);
$chars = Functions::flattenSingleValue($chars);
if ($chars < 0) {
if (!is_numeric($chars) || $chars < 0) {
return Functions::VALUE();
}

View File

@ -16,6 +16,16 @@ return [
'QWERTYUIOP',
-1,
],
[
'#VALUE!',
'QWERTYUIOP',
'NaN',
],
[
'#VALUE!',
'QWERTYUIOP',
null,
],
[
'ABC',
'ABCDEFGHI',

View File

@ -26,7 +26,19 @@ return [
-1,
],
[
'',
'#VALUE!',
'QWERTYUIOP',
'NaN',
1,
],
[
'#VALUE!',
'QWERTYUIOP',
2,
'NaN',
],
[
'#VALUE!',
'QWERTYUIOP',
5,
],

View File

@ -16,6 +16,16 @@ return [
'QWERTYUIOP',
-1,
],
[
'#VALUE!',
'QWERTYUIOP',
'NaN',
],
[
'#VALUE!',
'QWERTYUIOP',
null,
],
[
'GHI',
'ABCDEFGHI',