Skip to content

Commit 1662192

Browse files
committed
AC-7025 - Sanitize input handler parameter
1 parent 58a0fa1 commit 1662192

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework;
9+
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\Validator\RegexFactory;
12+
13+
class RegexValidator extends RegexFactory
14+
{
15+
16+
/**
17+
* @var RegexFactory
18+
*/
19+
private RegexFactory $regexValidatorFactory;
20+
21+
/**
22+
* Validation pattern for handles array
23+
*/
24+
private const VALIDATION_RULE_PATTERN = '/^[a-z0-9,.]+[a-z0-9_,.]*$/i';
25+
26+
/**
27+
* @param RegexFactory|null $regexValidatorFactory
28+
*/
29+
public function __construct(
30+
?RegexFactory $regexValidatorFactory = null
31+
) {
32+
$this->regexValidatorFactory = $regexValidatorFactory
33+
?: ObjectManager::getInstance()->get(RegexFactory::class);
34+
}
35+
36+
/**
37+
* Validates parameter regex
38+
*
39+
* @param string $params
40+
* @param string $pattern
41+
* @return bool
42+
*/
43+
public function validateParamRegex($params, $pattern = self::VALIDATION_RULE_PATTERN)
44+
{
45+
$validator = $this->regexValidatorFactory->create(['pattern' => $pattern]);
46+
47+
if ($params && !$validator->isValid($params)) {
48+
return false;
49+
}
50+
51+
return true;
52+
}
53+
}

0 commit comments

Comments
 (0)