Skip to content

fix: issue #1476 crash with numeric string value terminating with new line #1481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
],
];