]> granicus.if.org Git - php/commitdiff
Fix for bug #51192 (FILTER_VALIDATE_URL will invalidate a hostname that includes...
authorAdam Harvey <aharvey@php.net>
Wed, 3 Mar 2010 09:25:50 +0000 (09:25 +0000)
committerAdam Harvey <aharvey@php.net>
Wed, 3 Mar 2010 09:25:50 +0000 (09:25 +0000)
ext/filter/logical_filters.c
ext/filter/tests/bug51192.phpt [new file with mode: 0644]

index 0b27a641f2bb5e387d13825cab3a496a43433c49..52dcb504ecb488f9b31d0580712867c40c3bcf8a 100644 (file)
@@ -467,7 +467,7 @@ void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
                s = url->host;
 
                while (s < e) {
-                       if (!isalnum((int)*(unsigned char *)s) && *s != '_' && *s != '.') {
+                       if (!isalnum((int)*(unsigned char *)s) && *s != '-' && *s != '.') {
                                goto bad_url;
                        }
                        s++;
diff --git a/ext/filter/tests/bug51192.phpt b/ext/filter/tests/bug51192.phpt
new file mode 100644 (file)
index 0000000..96c67ea
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+bug 51192, FILTER_VALIDATE_URL will invalidate a hostname that includes '-'
+--SKIPIF--
+<?php if (!extension_loaded("filter")) die("skip"); ?>
+--FILE--
+<?php
+var_dump(filter_var('http://example.com/path', FILTER_VALIDATE_URL));
+var_dump(filter_var('http://exa-mple.com/path', FILTER_VALIDATE_URL));
+var_dump(filter_var('http://exa_mple.com/path', FILTER_VALIDATE_URL));
+--EXPECT--     
+string(23) "http://example.com/path"
+string(24) "http://exa-mple.com/path"
+bool(false)