Skip to content

Commit

Permalink
Fixed issue #9090: Valid IDNA e-mail address is considered incorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed Jun 18, 2014
1 parent 8be1ed5 commit b450e53
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 31 deletions.
49 changes: 49 additions & 0 deletions application/core/LSYii_EmailIDNAValidator.php
@@ -0,0 +1,49 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
* LimeSurvey
* Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
*/

class LSYii_EmailIDNAValidator extends CValidator {

public $allowEmpty=false;
public $allowMultiple=false;


public function validateAttribute($object,$attribute){

if ($object->$attribute=='' && $this->allowEmpty)
{
return;
}

if ($this->allowMultiple)
{
$aEmailAdresses=explode(';',$object->$attribute);
}
else
{
$aEmailAdresses=array($object->$attribute);
}

foreach ($aEmailAdresses as $sEmailAddress)
{
if (!validateEmailAddress($object->$attribute))
{
$this->addError($object, $attribute, gT('Invalid email address.'));
return;
}

}
return;
}

}
28 changes: 0 additions & 28 deletions application/core/LSYii_Validators.php
Expand Up @@ -166,33 +166,5 @@ public function multiLanguageFilter($value)
$aValue=array_map("sanitize_languagecode",$aValue);
return implode(" ",$aValue);
}

public function emailIDNA($value,$params){

if ($value='' && isset($params['allowEmpty']) && $params['allowEmpty'])
{
return $value;
}

if (isset($params['allowMultiple']) && $params['allowMultiple'])
{
$aEmailAdresses=explode(';',$value);
}
else
{
$aEmailAdresses=array($value);
}

foreach ($aEmailAdresses as $sEmailAddress)
{
if (!validateEmailAddress($value))
{
$this->addError($attribute, gT('Invalid email address.'));
return;
}

}
return $value;
}

}
1 change: 0 additions & 1 deletion application/models/Survey.php
Expand Up @@ -356,7 +356,6 @@ public function hasTokens($iSurveyID) {
* Creates a new survey - does some basic checks of the suppplied data
*
* @param array $aData Array with fieldname=>fieldcontents data
* @param boolean $xssfiltering Sets if the data for the new survey should be filtered for XSS
* @return integer The new survey id
*/
public function insertNewSurvey($aData)
Expand Down
2 changes: 1 addition & 1 deletion application/models/Token.php
Expand Up @@ -133,7 +133,7 @@ public function rules()
array(implode(',', $this->tableSchema->columnNames), 'safe'),
array('remindercount','numerical', 'integerOnly'=>true,'allowEmpty'=>true),
array('email','filter','filter'=>'trim'),
array('email','emailIDNA', 'allowEmpty'=>true, 'allowMultiple'=>true),
array('email','LSYii_EmailIDNAValidator', 'allowEmpty'=>true, 'allowMultiple'=>true),
array('usesleft','numerical', 'integerOnly'=>true,'allowEmpty'=>true),
array('mpid','numerical', 'integerOnly'=>true,'allowEmpty'=>true),
array('blacklisted', 'in','range'=>array('Y','N'), 'allowEmpty'=>true),
Expand Down
2 changes: 1 addition & 1 deletion application/models/TokenDynamic.php
Expand Up @@ -87,7 +87,7 @@ public function rules()
return array(
array('remindercount','numerical', 'integerOnly'=>true,'allowEmpty'=>true),
array('email','filter','filter'=>'trim'),
array('email','emailIDNA', 'allowEmpty'=>true, 'allowMultiple'=>true),
array('email','LSYii_EmailIDNAValidator', 'allowEmpty'=>true, 'allowMultiple'=>true),
array('usesleft','numerical', 'integerOnly'=>true,'allowEmpty'=>true),
array('mpid','numerical', 'integerOnly'=>true,'allowEmpty'=>true),
array('blacklisted', 'in','range'=>array('Y','N'), 'allowEmpty'=>true),
Expand Down

0 comments on commit b450e53

Please sign in to comment.