Fixes #8671: Extracted yii\helpers\Html::escapeJsRegularExpression() method from yii\validators\RegularExpressionValidator

This commit is contained in:
Dmitry Naumenko
2015-07-27 17:39:36 +03:00
committed by Alexander Makarov
parent aba7effa2b
commit b16d734c29
3 changed files with 28 additions and 13 deletions

View File

@ -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),