From 4a621f2f4e38377acb44c8e952cd3f403c43b9b3 Mon Sep 17 00:00:00 2001 From: "alexander.makarow" Date: Wed, 23 Mar 2011 22:00:50 +0000 Subject: [PATCH] CStringValidator now uses application charset by default if mb_strlen is available --- CHANGELOG | 1 + framework/validators/CStringValidator.php | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 21a7c5180..e1bab2b6d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -84,6 +84,7 @@ Version 1.1.7 to be released - Enh: Error page now displays associative array keys in parameter list (Sam Dark) - Enh: Added CController::getActionParams() and invalidActionParams() to allow customizing action parameter binding feature (Qiang) - Enh: Added CEvent::$params (Qiang) +- Enh: CStringValidator now uses application charset by default if mb_strlen is available (Sam Dark) - Chg #2001: CGridView now renders footer after the body content (Qiang) - Chg #2111: Calling CActiveRecord::getRelated($name, true) now will redo the DB query even if isNewRecord is true (qiang) - Chg #2144: Upgraded jQuery UI to version 1.8.11 (Sam Dark) diff --git a/framework/validators/CStringValidator.php b/framework/validators/CStringValidator.php index cce5d6906..e42e11763 100644 --- a/framework/validators/CStringValidator.php +++ b/framework/validators/CStringValidator.php @@ -48,9 +48,12 @@ class CStringValidator extends CValidator /** * @var string the encoding of the string value to be validated (e.g. 'UTF-8'). * Setting this property requires you to enable mbstring PHP extension. - * The value of this property will be used as the 2nd parameter of the mb_strlen() function. - * Defaults to false, which means the strlen() function will be used for calculating the length - * of the string. + * The value of this property will be used as the 2nd parameter of the + * mb_strlen() function. + * + * Defaults to application charset, which means the application charset + * will be used for calculating the length of the string if mb_strlen() is + * available and strlen() if it isn't. * @since 1.1.1 */ public $encoding=false; @@ -66,8 +69,9 @@ class CStringValidator extends CValidator $value=$object->$attribute; if($this->allowEmpty && $this->isEmpty($value)) return; - if($this->encoding!==false && function_exists('mb_strlen')) - $length=mb_strlen($value,$this->encoding); + + if(function_exists('mb_strlen')) + $length=mb_strlen($value,$this->encoding?$this->encoding:Yii::app()->charset); else $length=strlen($value); if($this->min!==null && $length<$this->min)