Selaa lähdekoodia

merged branch Seldaek/url_validator (PR #1370)

Commits
-------

159fc0e [Validator] Added symbols to IDNs validation
c827faf [Validator] Add support for IDNs and custom TLDs

Discussion
----------

[Validator] Add support for IDNs and custom TLDs

Minor changes to allow for IDNs and [custom TLDs](http://news.softpedia.com/news/ICANN-Approves-New-Custom-Generic-Top-Level-Domains-Like-google-bank-206977.shtml). This is the only sane way to support everything in a timeless manner.

---------------------------------------------------------------------------

by stealth35 at 2011/06/20 04:32:09 -0700

maybe it should be check the host with idn_to_ascii (if function exists, maybe it's should recreate un punycode en/decoder in the stub)

---------------------------------------------------------------------------

by mvrhov at 2011/06/20 04:40:10 -0700

/me :faceslap.
Haven't seen the link in PR

---------------------------------------------------------------------------

by Seldaek at 2011/06/20 04:40:40 -0700

@mvrhov: Yup, that's what pushed me to reconsider adding this.

@stealth35: I'm not sure if this is needed. I don't want this to be too strict, with another validator or with an extra option I think we can make a check that the domain actually exists, or do a GET / on it or something, but this just checks validity of the syntax.

---------------------------------------------------------------------------

by stealth35 at 2011/06/20 04:48:05 -0700

I understand :)
what about funny IDN like : [☎.com] (http://xn--y3h.com/) ?

---------------------------------------------------------------------------

by Seldaek at 2011/06/20 04:53:19 -0700

@stealth35: Fixed

---------------------------------------------------------------------------

by stealth35 at 2011/06/20 04:56:18 -0700

it's seem great,for acceptable chars [RFC] (http://www.faqs.org/rfcs/rfc3490.html) said (with UseSTD3ASCIIRules option) :

	(a) Verify the absence of non-LDH ASCII code points; that is, the
         absence of 0..2C, 2E..2F, 3A..40, 5B..60, and 7B..7F.
Fabien Potencier 14 vuotta sitten
vanhempi
commit
318ae129ad

+ 2 - 2
src/Symfony/Component/Validator/Constraints/UrlValidator.php

@@ -20,7 +20,7 @@ class UrlValidator extends ConstraintValidator
     const PATTERN = '~^
             (%s)://                                 # protocol
             (
-                ([a-z0-9-]+\.)+[a-z]{2,6}               # a domain name
+                ([\pL\pN\pS-]+\.)+[\pL]+                   # a domain name
                     |                                     #  or
                 \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}      # a IP address
                     |                                     #  or
@@ -30,7 +30,7 @@ class UrlValidator extends ConstraintValidator
             )
             (:[0-9]+)?                              # a port (optional)
             (/?|/\S+)                               # a /, nothing or a / with something
-        $~ix';
+        $~ixu';
 
     public function isValid($value, Constraint $constraint)
     {

+ 11 - 0
tests/Symfony/Tests/Component/Validator/Constraints/UrlValidatorTest.php

@@ -73,6 +73,17 @@ class UrlValidatorTest extends \PHPUnit_Framework_TestCase
             array('http://[::1]/'),
             array('http://[::1]:80/'),
             array('http://[1:2:3::4:5:6:7]/'),
+            array('http://sãopaulo.com/'),
+            array('http://sãopaulo.com.br/'),
+            array('http://пример.испытание/'),
+            array('http://مثال.إختبار/'),
+            array('http://例子.测试/'),
+            array('http://例子.測試/'),
+            array('http://例え.テスト/'),
+            array('http://مثال.آزمایشی/'),
+            array('http://실례.테스트/'),
+            array('http://العربية.idn.icann.org/'),
+            array('http://☎.com/'),
         );
     }