mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-02 04:37:42 +08:00
Fixes #8671: Extracted yii\helpers\Html::escapeJsRegularExpression() method from yii\validators\RegularExpressionValidator
This commit is contained in:
committed by
Alexander Makarov
parent
aba7effa2b
commit
b16d734c29
@ -9,6 +9,7 @@ namespace yii\validators;
|
||||
|
||||
use Yii;
|
||||
use yii\base\InvalidConfigException;
|
||||
use yii\helpers\Html;
|
||||
use yii\web\JsExpression;
|
||||
use yii\helpers\Json;
|
||||
|
||||
@ -64,19 +65,7 @@ class RegularExpressionValidator extends Validator
|
||||
*/
|
||||
public function clientValidateAttribute($model, $attribute, $view)
|
||||
{
|
||||
$pattern = $this->pattern;
|
||||
$pattern = preg_replace('/\\\\x\{?([0-9a-fA-F]+)\}?/', '\u$1', $pattern);
|
||||
$deliminator = substr($pattern, 0, 1);
|
||||
$pos = strrpos($pattern, $deliminator, 1);
|
||||
$flag = substr($pattern, $pos + 1);
|
||||
if ($deliminator !== '/') {
|
||||
$pattern = '/' . str_replace('/', '\\/', substr($pattern, 1, $pos - 1)) . '/';
|
||||
} else {
|
||||
$pattern = substr($pattern, 0, $pos + 1);
|
||||
}
|
||||
if (!empty($flag)) {
|
||||
$pattern .= preg_replace('/[^igm]/', '', $flag);
|
||||
}
|
||||
$pattern = Html::escapeJsRegularExpression($this->pattern);
|
||||
|
||||
$options = [
|
||||
'pattern' => new JsExpression($pattern),
|
||||
|
||||
Reference in New Issue
Block a user