Skip to content
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

TextData Coverage and Minor Bug Fixes #1744

Merged
merged 1 commit into from
Dec 10, 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
15 changes: 8 additions & 7 deletions src/PhpSpreadsheet/Calculation/TextData.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public static function CHARACTER($character)
{
$character = Functions::flattenSingleValue($character);

if ((!is_numeric($character)) || ($character < 0)) {
if (!is_numeric($character)) {
return Functions::VALUE();
}

if (function_exists('iconv')) {
return iconv('UCS-4LE', 'UTF-8', pack('V', $character));
$character = (int) $character;
if ($character < 1 || $character > 255) {
return Functions::VALUE();
}

return mb_convert_encoding('&#' . (int) $character . ';', 'UTF-8', 'HTML-ENTITIES');
return iconv('UCS-4LE', 'UTF-8', pack('V', $character));
}

/**
Expand Down Expand Up @@ -160,7 +160,7 @@ public static function DOLLAR($value = 0, $decimals = 2)

// Validate parameters
if (!is_numeric($value) || !is_numeric($decimals)) {
return Functions::NAN();
return Functions::VALUE();
}
$decimals = floor($decimals);

Expand All @@ -174,6 +174,7 @@ public static function DOLLAR($value = 0, $decimals = 2)
}
$value = MathTrig::MROUND($value, $round);
}
$mask = "$mask;($mask)";

return NumberFormat::toFormattedString($value, $mask);
}
Expand Down Expand Up @@ -265,7 +266,7 @@ public static function FIXEDFORMAT($value, $decimals = 2, $no_commas = false)

// Validate parameters
if (!is_numeric($value) || !is_numeric($decimals)) {
return Functions::NAN();
return Functions::VALUE();
}
$decimals = (int) floor($decimals);

Expand Down
28 changes: 22 additions & 6 deletions tests/data/Calculation/TextData/CHAR.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
'#VALUE!',
-5,
],
[
'#VALUE!',
0,
],
[
'A',
65,
Expand All @@ -22,27 +26,39 @@
126,
],
[
'⽇',
'Á',
193,
],
[
'ÿ',
255,
],
[
'#VALUE!',
256,
],
[
'#VALUE!', // '⽇',
12103,
],
[
'œ',
'#VALUE!', // 'œ',
0x153,
],
[
'ƒ',
'#VALUE!', // 'ƒ',
0x192,
],
[
'℅',
'#VALUE!', // '℅',
0x2105,
],
[
'∑',
'#VALUE!', // '∑',
0x2211,
],
[
'†',
'#VALUE!', // '†',
0x2020,
],
];
18 changes: 16 additions & 2 deletions tests/data/Calculation/TextData/DOLLAR.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@
123.456,
2,
],
[
'$123.46',
123.456,
],
[
'$123.32',
123.321,
2,
],
[
'($123.32)',
-123.321,
2,
],
[
'$1,235,000',
1234567,
Expand All @@ -22,12 +31,17 @@
-5,
],
[
'#NUM!',
'($1,200,000)',
-1234567,
-5,
],
[
'#VALUE!',
'ABC',
2,
],
[
'#NUM!',
'#VALUE!',
123.456,
'ABC',
],
Expand Down
32 changes: 30 additions & 2 deletions tests/data/Calculation/TextData/FIXED.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,41 @@
true,
],
[
'#NUM!',
'-123456.79',
-123456.789,
2,
true,
],
[
'123500',
123456.789,
-2,
true,
],
[
'123,500',
123456.789,
-2,
],
[
'-123500',
-123456.789,
-2,
true,
],
[
'-123,500',
-123456.789,
-2,
],
[
'#VALUE!',
'ABC',
2,
null,
],
[
'#NUM!',
'#VALUE!',
123.456,
'ABC',
null,
Expand Down
5 changes: 5 additions & 0 deletions tests/data/Calculation/TextData/SEARCH.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
'Mark Baker',
2,
],
[
1,
'',
'Mark Baker',
],
[
'#VALUE!',
'BITE',
Expand Down