php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51192 FILTER_VALIDATE_URL will invalidate a hostname that includes '-'
Submitted: 2010-03-03 08:49 UTC Modified: 2012-07-26 18:58 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: solar at azrael dot ws Assigned: aharvey
Status: Closed Package: Filter related
PHP Version: 5.2.13 OS: linux
Private report: No CVE-ID:
 [2010-03-03 08:49 UTC] solar at azrael dot ws
Description:
------------
Hostname must contain only alpha-numeric letters and the hyphen(-).

Test script:
---------------
var_dump(filter_var(

Expected result:
----------------
string(18) "http://example.com"
string(19) "http://exa-mple.com"
bool(false)

Actual result:
--------------
string(18) "http://example.com"
bool(false)
string(19) "http://exa_mple.com"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-03 08:56 UTC] solar at azrael dot ws
Oops.

Test script:

var_dump(filter_var('http://example.com', FILTER_VALIDATE_URL));
var_dump(filter_var('http://exa-mple.com', FILTER_VALIDATE_URL));
var_dump(filter_var('http://exa_mple.com', FILTER_VALIDATE_URL));
 [2010-03-03 09:41 UTC] solar at azrael dot ws
Changes summary. That was too long.
 [2010-03-03 09:50 UTC] aharvey@php.net
-Status: Open +Status: Assigned
 [2010-03-03 09:50 UTC] aharvey@php.net
Yeah, that doesn't quite look right. :)

Cheers for the patch; I'll cook up a test script to go with it and commit it.
 [2010-03-03 10:25 UTC] aharvey@php.net
Automatic comment from SVN on behalf of aharvey
Revision: http://svn.php.net/viewvc/?view=revision&revision=295773
Log: Fix for bug #51192 (FILTER_VALIDATE_URL will invalidate a hostname that includes '-'). Original patch by solar@azrael.ws.
 [2010-03-03 10:26 UTC] aharvey@php.net
-Status: Assigned +Status: Closed
 [2010-03-03 10:26 UTC] aharvey@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2010-04-06 22:04 UTC] lupo at e-noise dot com
I am experiencing the same behavior with PHP 5.3.2 on Mac OSX. When hostname contains hyphens filter_var() won't validate using the FILTER_VALIDATE_URL filter.

The test code posted by "solar at azrael dot ws" produces the following output:

string(18) "http://example.com"
bool(false)
string(19) "http://exa_mple.com"
 [2010-04-07 02:43 UTC] aharvey@php.net
The fix for this hasn't been incorporated into any stable releases yet: it came after 5.2.13 was released and 5.3.2 was branched (and far too late in 5.3.2's release cycle to be ported across).

Both versions 5.2.14 and 5.3.3 will include this bug fix.
 [2010-08-13 08:39 UTC] ondrej@php.net
Please be aware that IDN (PunyCode) url can contain two consecutive hyphens, ie.

xn--hkyrky-ptac70bc.cz

is OK as well.
 [2010-08-13 08:49 UTC] aharvey@php.net
That also works as of 5.3.3 -- I actually own a couple of internationalised domains, so I'm aware of the issue. :)
 [2012-07-26 14:28 UTC] bd9161b68a85 at e89800344727 dot anonbox dot net
Can you please fix it after years of ignoring it?
 [2012-07-26 18:58 UTC] rasmus@php.net
Years of ignoring what? This was fixed years ago in PHP 5.3.3
 [2014-01-06 20:54 UTC] skedat at gmail dot com
php 5.4.4 on Windows this error still exists.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Thu Apr 24 19:01:53 2014 UTC