浏览代码

Merge pull request #13327 from nextcloud/allow-bracket-notation-for-remove-ipv6-address

Allow bracket IPv6 address format inside IPAdress Normalizer
tags/v16.0.0beta1
Morris Jobke 5 年前
父节点
当前提交
d004164fcc
没有帐户链接到提交者的电子邮件
共有 2 个文件被更改,包括 7 次插入0 次删除
  1. 3
    0
      lib/private/Security/Normalizer/IpAddress.php
  2. 4
    0
      tests/lib/Security/Normalizer/IpAddressTest.php

+ 3
- 0
lib/private/Security/Normalizer/IpAddress.php 查看文件

@@ -68,6 +68,9 @@ class IpAddress {
* @return string
*/
private function getIPv6Subnet(string $ip, int $maskBits = 48): string {
if ($ip[0] === '[' && $ip[-1] === ']') { // If IP is with brackets, for example [::1]
$ip = substr($ip, 1, strlen($ip) - 2);
}
$binary = \inet_pton($ip);
for ($i = 128; $i > $maskBits; $i -= 8) {
$j = \intdiv($i, 8) - 1;

+ 4
- 0
tests/lib/Security/Normalizer/IpAddressTest.php 查看文件

@@ -40,6 +40,10 @@ class IpAddressTest extends TestCase {
'2001:0db8:85a3:0000:0000:8a2e:0370:7334',
'2001:db8:85a3::8a2e:370:7334/128',
],
[
'[::1]',
'::1/128',
],
];
}


正在加载...
取消
保存