Skip to content

Commit

Permalink
fix: issue #1476 crash with numeric string value terminating with new…
Browse files Browse the repository at this point in the history
… line (#1481)

* fix: issue #1476 crash with numeric string value terminating with new line
* test: provided tests for issue #1476
  • Loading branch information
giannign1 authored May 23, 2020
1 parent be415fa commit 7b1957f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
- Fix RATE, PRICE, XIRR, and XNPV Functions [#1456](https://github.com/PHPOffice/PhpSpreadsheet/pull/1456)
- Save Excel 2010+ functions properly in XLSX [#1461](https://github.com/PHPOffice/PhpSpreadsheet/pull/1461)
- Several improvements in HTML writer [#1464](https://github.com/PHPOffice/PhpSpreadsheet/pull/1464)
- Fix Crash while trying setting a cell the value "123456\n" [#1476](https://github.com/PHPOffice/PhpSpreadsheet/pull/1481)

### Changed

Expand Down
2 changes: 2 additions & 0 deletions src/PhpSpreadsheet/Cell/DefaultValueBinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public static function dataTypeForValue($pValue)
return DataType::TYPE_STRING;
} elseif ((strpos($pValue, '.') === false) && ($pValue > PHP_INT_MAX)) {
return DataType::TYPE_STRING;
} elseif (!is_numeric($pValue)) {
return DataType::TYPE_STRING;
}

return DataType::TYPE_NUMERIC;
Expand Down
1 change: 1 addition & 0 deletions tests/PhpSpreadsheetTests/Cell/DefaultValueBinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function binderProvider()
['#REF!'],
[new DateTime()],
[new DateTimeImmutable()],
['123456\n'],
];
}

Expand Down
4 changes: 4 additions & 0 deletions tests/data/Cell/DefaultValueBinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,8 @@
'e',
'#DIV/0!',
],
[
's',
'123456\n',
],
];

0 comments on commit 7b1957f

Please sign in to comment.