mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
Merge branch '3.3.x'
This commit is contained in:
commit
5d7335671e
2 changed files with 58 additions and 1 deletions
|
@ -2842,7 +2842,7 @@ function get_censor_preg_expression($word)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the first block of the specified IPv6 address and as many additional
|
* Returns the first block of the specified IPv6 address and as many additional
|
||||||
* ones as specified in the length paramater.
|
* ones as specified in the length parameter.
|
||||||
* If length is zero, then an empty string is returned.
|
* If length is zero, then an empty string is returned.
|
||||||
* If length is greater than 3 the complete IP will be returned
|
* If length is greater than 3 the complete IP will be returned
|
||||||
*/
|
*/
|
||||||
|
@ -2853,6 +2853,14 @@ function short_ipv6($ip, $length)
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle IPv4 embedded IPv6 addresses
|
||||||
|
if (preg_match('/(?:\d{1,3}\.){3}\d{1,3}$/i', $ip))
|
||||||
|
{
|
||||||
|
$binary_ip = inet_pton($ip);
|
||||||
|
$ip_v6 = $binary_ip ? inet_ntop($binary_ip) : $ip;
|
||||||
|
$ip = $ip_v6 ?: $ip;
|
||||||
|
}
|
||||||
|
|
||||||
// extend IPv6 addresses
|
// extend IPv6 addresses
|
||||||
$blocks = substr_count($ip, ':') + 1;
|
$blocks = substr_count($ip, ':') + 1;
|
||||||
if ($blocks < 9)
|
if ($blocks < 9)
|
||||||
|
|
49
tests/functions/short_ipv6__test.php
Normal file
49
tests/functions/short_ipv6__test.php
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This file is part of the phpBB Forum Software package.
|
||||||
|
*
|
||||||
|
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||||
|
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||||
|
*
|
||||||
|
* For full copyright and license information, please see
|
||||||
|
* the docs/CREDITS.txt file.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class short_ipv6__test extends phpbb_test_case
|
||||||
|
{
|
||||||
|
public function data_short_ipv6(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['::1', 0, ''],
|
||||||
|
['::1', 1, '0000:0000'],
|
||||||
|
['::1', 2, '0000:0000:0000'],
|
||||||
|
['::1', 3, '0000:0000:0000:0000'],
|
||||||
|
['::1', 4, '0000:0000:0000:0000:0000:0000:0000:1'],
|
||||||
|
['2001:db8:3333:4444:5555:6666:7777:8888', 0, ''],
|
||||||
|
['2001:db8:3333:4444:5555:6666:7777:8888', 1, '2001:db8'],
|
||||||
|
['2001:db8:3333:4444:5555:6666:7777:8888', 2, '2001:db8:3333'],
|
||||||
|
['2001:db8:3333:4444:5555:6666:7777:8888', 3, '2001:db8:3333:4444'],
|
||||||
|
['2001:db8:3333:4444:5555:6666:7777:8888', 4, '2001:db8:3333:4444:5555:6666:7777:8888'],
|
||||||
|
['::ffff:192.168.1.1', 0, ''],
|
||||||
|
['::ffff:192.168.1.1', 1, '0000:0000'],
|
||||||
|
['::ffff:192.168.1.1', 2, '0000:0000:0000'],
|
||||||
|
['::ffff:192.168.1.1', 3, '0000:0000:0000:0000'],
|
||||||
|
['::ffff:192.168.1.1', 4, '0000:0000:0000:0000:0000:0000:ffff:192.168.1.1'],
|
||||||
|
['FADE:BAD::192.168.0.1', 0, ''],
|
||||||
|
['FADE:BAD::192.168.0.1', 1, 'fade:bad'],
|
||||||
|
['FADE:BAD::192.168.0.1', 2, 'fade:bad:0000'],
|
||||||
|
['FADE:BAD::192.168.0.1', 3, 'fade:bad:0000:0000'],
|
||||||
|
['FADE:BAD::192.168.0.1', 4, 'fade:bad:0000:0000:0000:0000:c0a8:1'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider data_short_ipv6
|
||||||
|
*/
|
||||||
|
public function test_short_ipv6($ip, $length, $expected)
|
||||||
|
{
|
||||||
|
$this->assertEquals($expected, short_ipv6($ip, $length));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue