This repository has been archived by the owner on May 27, 2022. It is now read-only.
forked from phadej/igbinary
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* commit 'tricky/master': Fixup against NaN Add 0 and -0 Also skip test if mcrypt is not available. Closures cannot be serialized. Add test for double Inf, -Inf, and NaN. Another rm check
- Loading branch information
Showing
3 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--TEST-- | ||
Check for double NaN, Inf, -Inf, 0, and -0 | ||
--FILE-- | ||
<?php | ||
function test($type, $variable) { | ||
$serialized = igbinary_serialize($variable); | ||
$unserialized = igbinary_unserialize($serialized); | ||
|
||
echo $type, ":\n"; | ||
var_dump($variable); | ||
var_dump($unserialized); | ||
|
||
echo substr(bin2hex($serialized), 8), "\n"; | ||
echo "\n"; | ||
} | ||
|
||
test('double NaN', NAN); | ||
test('double Inf', INF); | ||
test('double -Inf', -INF); | ||
test('double 0.0', 0.0); | ||
test('double -0.0', -0.0); | ||
|
||
--EXPECTF-- | ||
double NaN: | ||
float(NAN) | ||
float(NAN) | ||
%r0c[7f]ff0*[^0]0*%r | ||
|
||
double Inf: | ||
float(INF) | ||
float(INF) | ||
0c7ff0000000000000 | ||
|
||
double -Inf: | ||
float(-INF) | ||
float(-INF) | ||
0cfff0000000000000 | ||
|
||
double 0.0: | ||
float(0) | ||
float(0) | ||
0c0000000000000000 | ||
|
||
double -0.0: | ||
float(0) | ||
float(0) | ||
0c0000000000000000 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--TEST-- | ||
Closure | ||
--SKIPIF-- | ||
<?php | ||
if(!extension_loaded('igbinary')) { | ||
echo "skip no igbinary"; | ||
} | ||
|
||
if (version_compare(PHP_VERSION, '5.3.0') < 0) { | ||
echo "skip closures only for PHP 5.3.0+"; | ||
} | ||
--FILE-- | ||
<?php | ||
|
||
$closure = function ($x) { | ||
return $x + 1; | ||
}; | ||
|
||
class Foo implements Serializable { | ||
public function serialize() { | ||
echo "Should not be run.\n"; | ||
} | ||
|
||
public function unserialize($str) { | ||
echo "Should not be run.\n"; | ||
} | ||
} | ||
|
||
$array = array($closure, new Foo()); | ||
|
||
try { | ||
$ser = igbinary_serialize($array); | ||
echo "Serialized closure.\n"; | ||
$unser = igbinary_unserialize($ser); | ||
echo "Unserialized closure.\n"; | ||
var_dump($unser); | ||
} catch (Exception $e) { | ||
echo "Got exception.\n"; | ||
} | ||
--EXPECT-- | ||
Got exception. |