alpha, xss_clean and i18n in CI

#1
[eluser]Crimp[/eluser]
I have been trying to resolve two CI issues:

Validation.php -> all TRUE alpha-based functions are ASCII only
Input.php -> xss_clean silently returns an empty $_POST value if entry string is not ASCII

Both problems are already documented in the forums. Unless hacked, these core functions are not usable for anyone outside the basic ASCII geography (not even the ISO-8859-1 folks).

I have attempted, as a start, to change the locale and alter the relevant regexp patterns in Validation.php, but it fails. It seems, to me, that PCRE does not support the extended ASCII charsets despite first checking and then setting the correct locale. I hope someone may be able to assist with this to help resolve these issues. Some example snippets:

CI Validation.php alpha():
Code:
function alpha($str)
    {
        return ( ! preg_match("/^([a-z])+$/i", $str)) ? FALSE : TRUE;
    }

Checking locale (varies according to your region, of course):
Code:
$loc_no = setlocale(LC_ALL, 'no_no', 'no_NO', 'nb_NO','nb_NO.ISO-8859-1','no_NO.ISO-88591');
echo "Preferred locale on this system is '$loc_no'";

Setting tested locale:
Code:
setlocale(LC_ALL, 'no_no');

Replacement pattern:
Code:
function alpha($str)
    {
        return ( ! preg_match("/^([a-zæøåÆØÅ])+$/i", $str)) ? FALSE : TRUE;
    }

Validation strings containing the extra chars still return FALSE. Then there's the bigger xss_clean issue. Has anyone resolved these i18n issues with CI, or just written their own callbacks instead (perhaps a better approach than always hacking the core?), or just turned off those rules and hoped for the best?

#2
[eluser]Crimp[/eluser]
Anyways:

Code:
function alpha_check($str)
    {    
        setlocale(LC_ALL, 'your locale');
        
        if (!ctype_alpha($str)) {
        
            $this->validation->set_message('alpha_check', 'Your error message.');
            return FALSE;
        
        } else {
        
            return TRUE;
        
        }
        
    }
Code:
function alphanumeric_check($str)
    {
        setlocale(LC_ALL, 'your locale');
        
        if (!ctype_alnum($str)) {
        
            $this->validation->set_message('alphanumeric_check', 'Your error message.');
            return FALSE;
        
        } else {
        
            return TRUE;
        
        }
        
    }


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.