Skip to content

Commit 0f214e4

Browse files
committed
PageCache/AccessList: Fix validation, handle multi value
1 parent 1418058 commit 0f214e4

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

app/code/Magento/PageCache/Model/System/Config/Backend/AccessList.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,22 @@ public function beforeSave()
2424
parent::beforeSave();
2525

2626
$value = $this->getValue();
27-
if (!is_string($value) || !preg_match('/^[\w\s\.\-\,\:(\/\d+)?]+$/', $value)) {
27+
28+
if (is_string($value)) {
29+
foreach (explode(',', $value) as $item) {
30+
if (!preg_match('/^[\w\.\-\:]+(\/(?:[0-9]|[12][0-9]|3[0-2]))?$/', trim($item))) {
31+
throw new LocalizedException(
32+
new Phrase(
33+
'Access List value "%1" is not valid because of item "%2". Please use only IP addresses and host names.',
34+
[$value, $item]
35+
)
36+
);
37+
}
38+
}
39+
} else {
2840
throw new LocalizedException(
2941
new Phrase(
30-
'Access List value "%1" is not valid. '
31-
. 'Please use only IP addresses and host names.',
42+
'Access List value "%1" is not valid. Please use only IP addresses and host names.',
3243
[$value]
3344
)
3445
);

app/code/Magento/PageCache/Test/Unit/Model/System/Config/Backend/AccessListTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ protected function setUp(): void
4848
public static function getValidValues(): array
4949
{
5050
return [
51+
['', 'localhost'],
5152
['localhost', 'localhost'],
5253
[null, 'localhost'],
5354
['127.0.0.1', '127.0.0.1'],
@@ -74,9 +75,11 @@ public function testBeforeSave($value, $expectedValue)
7475
public static function getInvalidValues(): array
7576
{
7677
return [
78+
[123],
7779
['\\bull val\\'],
7880
['{*I am not an IP*}'],
7981
['{*I am not an IP*}, 127.0.0.1'],
82+
['172.16.0.1/33'],
8083
];
8184
}
8285

0 commit comments

Comments
 (0)