Merge #15556 - Fix Long2IP issue with PHP7.1
Pull-request: #15556 Fixes: #14906 Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
commit
59d6fbec82
@ -9,6 +9,7 @@
|
||||
namespace PhpMyAdmin\Plugins\Transformations\Abs;
|
||||
|
||||
use PhpMyAdmin\Plugins\TransformationsPlugin;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
/**
|
||||
* Provides common methods for all of the long to IPv4 transformations plugins.
|
||||
@ -41,14 +42,13 @@ abstract class LongToIPv4TransformationsPlugin extends TransformationsPlugin
|
||||
*/
|
||||
public function applyTransformation($buffer, array $options = array(), $meta = '')
|
||||
{
|
||||
if ($buffer < 0 || $buffer > 4294967295) {
|
||||
if (! Util::isInteger($buffer) || $buffer < 0 || $buffer > 4294967295) {
|
||||
return htmlspecialchars($buffer);
|
||||
}
|
||||
|
||||
return long2ip($buffer);
|
||||
return long2ip((int) $buffer);
|
||||
}
|
||||
|
||||
|
||||
/* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
|
||||
|
||||
/**
|
||||
|
||||
@ -45,15 +45,18 @@ class Text_Plain_Binarytoip extends TransformationsPlugin
|
||||
*/
|
||||
public function applyTransformation($buffer, array $options = array(), $meta = '')
|
||||
{
|
||||
$length = strlen($buffer);
|
||||
if ($length == 4 || $length == 16) {
|
||||
$val = @inet_ntop(pack('A' . $length, $buffer));
|
||||
if ($val !== false) {
|
||||
return $val;
|
||||
}
|
||||
if (0 !== strpos($buffer, '0x')) {
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
return $buffer;
|
||||
$ipHex = substr($buffer, 2);
|
||||
$ipBin = hex2bin($ipHex);
|
||||
|
||||
if (false === $ipBin) {
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
return @inet_ntop($ipBin);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -4741,4 +4741,16 @@ class Util
|
||||
|
||||
return self::linkOrButton($url, $title . $orderImg, $orderLinkParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that input is an int or an int in a string
|
||||
*
|
||||
* @param mixed $input
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isInteger($input)
|
||||
{
|
||||
return (ctype_digit((string) $input));
|
||||
}
|
||||
}
|
||||
|
||||
@ -944,6 +944,26 @@ class TransformationPluginsTest extends PmaTestCase
|
||||
),
|
||||
'suffixMA_suffix'
|
||||
),
|
||||
array(
|
||||
new Text_Plain_Longtoipv4(),
|
||||
array(168496141),
|
||||
'10.11.12.13'
|
||||
),
|
||||
array(
|
||||
new Text_Plain_Longtoipv4(),
|
||||
array('168496141'),
|
||||
'10.11.12.13'
|
||||
),
|
||||
array(
|
||||
new Text_Plain_Longtoipv4(),
|
||||
array('my ip'),
|
||||
'my ip'
|
||||
),
|
||||
array(
|
||||
new Text_Plain_Longtoipv4(),
|
||||
array('<my ip>'),
|
||||
'<my ip>'
|
||||
)
|
||||
);
|
||||
|
||||
if (function_exists('imagecreatetruecolor')) {
|
||||
|
||||
@ -2128,4 +2128,51 @@ class UtilTest extends PmaTestCase
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Util::isInteger
|
||||
*
|
||||
* @param bool $expected Expected result for a given input
|
||||
* @param mixed $input Input data to check
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerIsInteger
|
||||
*/
|
||||
public function testIsInteger($expected, $input)
|
||||
{
|
||||
$isInteger = Util::isInteger($input);
|
||||
$this->assertEquals($expected, $isInteger);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for Util::isInteger test
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerIsInteger()
|
||||
{
|
||||
return [
|
||||
[
|
||||
true,
|
||||
1000,
|
||||
],
|
||||
[
|
||||
true,
|
||||
'1000',
|
||||
],
|
||||
[
|
||||
false,
|
||||
1000.1,
|
||||
],
|
||||
[
|
||||
false,
|
||||
'1000.1',
|
||||
],
|
||||
[
|
||||
false,
|
||||
'input',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user