[BUGFIX] Validation of umlaut URLs and mail addresses
authorMario Rimann <typo3-coding@rimann.org>
Thu, 24 Nov 2011 22:38:16 +0000 (23:38 +0100)
committerTolleiv Nietsch <info@tolleiv.de>
Wed, 7 Mar 2012 07:24:49 +0000 (08:24 +0100)
Adds IDN support to t3lib_div's validating methods for email
addresses and URLs.

Change-Id: Iaff6d43c54ce4a2567b46acfe449e33b89136f8d
Resolves: #30311
Releases: 4.8, 4.7, 4.6, 4.5
Reviewed-on: http://review.typo3.org/6907
Reviewed-by: Tolleiv Nietsch
Tested-by: Tolleiv Nietsch
t3lib/class.t3lib_div.php
tests/t3lib/class.t3lib_divTest.php

index cdea68a..4bb07a8 100644 (file)
@@ -1259,7 +1259,10 @@ final class t3lib_div {
                if (strlen($email) > 320) {
                        return FALSE;
                }
-               return (filter_var($email, FILTER_VALIDATE_EMAIL) !== FALSE);
+               require_once('../typo3/contrib/idna/idna_convert.class.php');
+               $IDN = new idna_convert(array('idn_version' => 2008));
+
+               return (filter_var($IDN->encode($email), FILTER_VALIDATE_EMAIL) !== FALSE);
        }
 
        /**
@@ -1509,7 +1512,10 @@ final class t3lib_div {
         * @return boolean Whether the given URL is valid
         */
        public static function isValidUrl($url) {
-               return (filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED) !== FALSE);
+               require_once('../typo3/contrib/idna/idna_convert.class.php');
+               $IDN = new idna_convert(array('idn_version' => 2008));
+
+               return (filter_var($IDN->encode($url), FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED) !== FALSE);
        }
 
 
index dccbe98..baeb90b 100644 (file)
@@ -742,6 +742,8 @@ class t3lib_divTest extends tx_phpunit_testcase {
                        // 'dot in local part' => array('firstname.lastname@employee.2something.com'),
                                // Fix / change if TYPO3 php requirement changed: Address ok with 5.2.6, but not ok with 5.3.2
                        // 'dash as local part' => array('-@foo.com'),
+                       'umlauts in local part' => array('äöüfoo@bar.com'),
+                       'umlauts in domain part' => array('foo@äöüfoo.com'),
                );
        }
 
@@ -1321,6 +1323,11 @@ class t3lib_divTest extends tx_phpunit_testcase {
                        'news' => array('news:news.php.net'),
                        'telnet'=> array('telnet://192.0.2.16:80/'),
                        'ldap' => array('ldap://[2001:db8::7]/c=GB?objectClass?one'),
+                       'http punycode domain name' => array('http://www.xn--bb-eka.at'),
+                       'http punicode subdomain' => array('http://xn--h-zfa.oebb.at'),
+                       'http domain-name umlauts' => array('http://www.öbb.at'),
+                       'http subdomain umlauts' => array('http://äh.oebb.at'),
+                       'http directory umlauts' => array('http://www.oebb.at/äöü/'),
                );
        }
 
@@ -3659,4 +3666,4 @@ class t3lib_divTest extends tx_phpunit_testcase {
                $this->assertEquals($expected, $result);
        }
 }
-?>
\ No newline at end of file
+?>