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:
parent
c4ed0ee7b0
commit
f81ffd9a4f
|
|
@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Fixed issue with Xlsx@listWorksheetInfo not returning any data
|
- 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
|
## 1.17.1 - 2021-03-01
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -299,7 +299,7 @@ class TextData
|
||||||
$value = Functions::flattenSingleValue($value);
|
$value = Functions::flattenSingleValue($value);
|
||||||
$chars = Functions::flattenSingleValue($chars);
|
$chars = Functions::flattenSingleValue($chars);
|
||||||
|
|
||||||
if ($chars < 0) {
|
if (!is_numeric($chars) || $chars < 0) {
|
||||||
return Functions::VALUE();
|
return Functions::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -325,7 +325,7 @@ class TextData
|
||||||
$start = Functions::flattenSingleValue($start);
|
$start = Functions::flattenSingleValue($start);
|
||||||
$chars = Functions::flattenSingleValue($chars);
|
$chars = Functions::flattenSingleValue($chars);
|
||||||
|
|
||||||
if (($start < 1) || ($chars < 0)) {
|
if (!is_numeric($start) || $start < 1 || !is_numeric($chars) || $chars < 0) {
|
||||||
return Functions::VALUE();
|
return Functions::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -333,10 +333,6 @@ class TextData
|
||||||
$value = ($value) ? Calculation::getTRUE() : Calculation::getFALSE();
|
$value = ($value) ? Calculation::getTRUE() : Calculation::getFALSE();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($chars)) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
return mb_substr($value, --$start, $chars, 'UTF-8');
|
return mb_substr($value, --$start, $chars, 'UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -353,7 +349,7 @@ class TextData
|
||||||
$value = Functions::flattenSingleValue($value);
|
$value = Functions::flattenSingleValue($value);
|
||||||
$chars = Functions::flattenSingleValue($chars);
|
$chars = Functions::flattenSingleValue($chars);
|
||||||
|
|
||||||
if ($chars < 0) {
|
if (!is_numeric($chars) || $chars < 0) {
|
||||||
return Functions::VALUE();
|
return Functions::VALUE();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,16 @@ return [
|
||||||
'QWERTYUIOP',
|
'QWERTYUIOP',
|
||||||
-1,
|
-1,
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'#VALUE!',
|
||||||
|
'QWERTYUIOP',
|
||||||
|
'NaN',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'#VALUE!',
|
||||||
|
'QWERTYUIOP',
|
||||||
|
null,
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'ABC',
|
'ABC',
|
||||||
'ABCDEFGHI',
|
'ABCDEFGHI',
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,19 @@ return [
|
||||||
-1,
|
-1,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'',
|
'#VALUE!',
|
||||||
|
'QWERTYUIOP',
|
||||||
|
'NaN',
|
||||||
|
1,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'#VALUE!',
|
||||||
|
'QWERTYUIOP',
|
||||||
|
2,
|
||||||
|
'NaN',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'#VALUE!',
|
||||||
'QWERTYUIOP',
|
'QWERTYUIOP',
|
||||||
5,
|
5,
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,16 @@ return [
|
||||||
'QWERTYUIOP',
|
'QWERTYUIOP',
|
||||||
-1,
|
-1,
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'#VALUE!',
|
||||||
|
'QWERTYUIOP',
|
||||||
|
'NaN',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'#VALUE!',
|
||||||
|
'QWERTYUIOP',
|
||||||
|
null,
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'GHI',
|
'GHI',
|
||||||
'ABCDEFGHI',
|
'ABCDEFGHI',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue