You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- [x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)
The error can be triggered if the advanced value binder is used and a value of "407 /" is set at a cell.
<?phprequire__DIR__ . '/vendor/autoload.php';
// Create new Spreadsheet object$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
// Use the advanced value binder
\PhpOffice\PhpSpreadsheet\Cell\Cell::setValueBinder(new \PhpOffice\PhpSpreadsheet\Cell\AdvancedValueBinder());
// Create spreadsheet$spreadsheet = newSpreadsheet();
$activeWorksheet = $spreadsheet->getActiveSheet();
$activeWorksheet->setCellValue('A1', '16 3/4');
// Error on the following line$activeWorksheet->setCellValue('A2', '407 / ');
What features do you think are causing the issue
Reader
Writer
Styles
Data Validations
Formula Calculations
Charts
AutoFilter
Form Elements
The problem comes from the advanced value binder. It is issued at the method setImproperFraction() at line 117 where the matches of a regexp are used in a division. The method setImproperFraction() is called from bindValue() on line 51.
The regular expression on line 50 is faulty. It looks like this: /^([+-]?)(\d*) +(\d*)\s?\/\s*(\d*)$/. Because the \d are marked with a * they can be omitted completely. So even a string like / would match that regular expression. In my opinion the * should be + so that at least one digit is required. It should look like this: /^([+-]?)(\d+) +(\d+)\s?\/\s*(\d+)$/.
Interestingly the regexp just two lines above (line 48) uses \d+, so it might be just an oversight that it is not also fixed on line 50.
Does an issue affect all spreadsheet file formats? If not, which formats are affected?
Yes.
Which versions of PhpSpreadsheet and PHP are affected?
1.29.0
The text was updated successfully, but these errors were encountered:
oleibman
added a commit
to oleibman/PhpSpreadsheet
that referenced
this issue
Jan 10, 2024
This is:
What is the expected behavior?
No fatal PHP error is issued.
What is the current behavior?
Fatal PHP error is issued:
What are the steps to reproduce?
The error can be triggered if the advanced value binder is used and a value of "407 /" is set at a cell.
What features do you think are causing the issue
The problem comes from the advanced value binder. It is issued at the method setImproperFraction() at line 117 where the matches of a regexp are used in a division. The method setImproperFraction() is called from bindValue() on line 51.
The regular expression on line 50 is faulty. It looks like this:
/^([+-]?)(\d*) +(\d*)\s?\/\s*(\d*)$/
. Because the\d
are marked with a*
they can be omitted completely. So even a string like/
would match that regular expression. In my opinion the*
should be+
so that at least one digit is required. It should look like this:/^([+-]?)(\d+) +(\d+)\s?\/\s*(\d+)$/
.Interestingly the regexp just two lines above (line 48) uses
\d+
, so it might be just an oversight that it is not also fixed on line 50.Does an issue affect all spreadsheet file formats? If not, which formats are affected?
Yes.
Which versions of PhpSpreadsheet and PHP are affected?
1.29.0
The text was updated successfully, but these errors were encountered: