Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,22 @@ public function beforeSave()
parent::beforeSave();

$value = $this->getValue();
if (!is_string($value) || !preg_match('/^[\w\s\.\-\,\:]+$/', $value)) {

if (is_string($value)) {
foreach (explode(',', $value) as $item) {
if (!preg_match('/^[\w\.\-\:]+(\/(?:[0-9]|[12][0-9]|3[0-2]))?$/', trim($item))) {
throw new LocalizedException(
new Phrase(
'Access List value "%1" is not valid because of item "%2". Please use only IP addresses and host names.',
[$value, $item]
)
);
}
}
} else {
throw new LocalizedException(
new Phrase(
'Access List value "%1" is not valid. '
. 'Please use only IP addresses and host names.',
'Access List value "%1" is not valid. Please use only IP addresses and host names.',
[$value]
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ protected function setUp(): void
public static function getValidValues(): array
{
return [
['', 'localhost'],
['localhost', 'localhost'],
[null, 'localhost'],
['127.0.0.1', '127.0.0.1'],
['127.0.0.1, localhost, ::2', '127.0.0.1, localhost, ::2'],
['172.16.0.1/24, 2001:0db8:/32', '172.16.0.1/24, 2001:0db8:/32'],
];
}

Expand All @@ -73,9 +75,11 @@ public function testBeforeSave($value, $expectedValue)
public static function getInvalidValues(): array
{
return [
[123],
['\\bull val\\'],
['{*I am not an IP*}'],
['{*I am not an IP*}, 127.0.0.1'],
['172.16.0.1/33'],
];
}

Expand Down