Edit report at https://bugs.php.net/bug.php?id=64948&edit=1
ID: 64948
Comment by: luke at reviews dot co dot uk
Reported by: neclimdul at gmail dot com
Summary: FILTER_VALIDATE_URL does not see urls with
underscores as valid URLs.
Status: Open
Type: Bug
Package: Filter related
Operating System: Ubuntu
PHP Version: 5.4.15
Block user comment: N
Private report: N
New Comment:
Definitely won't fix? parse_url() handles underscores quite nicely.
Previous Comments:
------------------------------------------------------------------------
[2015-08-21 17:14:03] rich at social5 dot com
The very Stack Overflow link aharvey@php.net referenced seems to suggest that FILTER_VALIDATE_URL
*should* allow underscores, does it not?
Regardless, ultimately, FILTER_VALIDATE_URL is used "in the wild" to verify whether or not
accessing a URL will load a web resource. There certainly *are* many sites that use underscores in
both the main domain as well as the subdomain. Regardless of the "lawyer material" (which
one could argue is in favor of "allowing" underscores, anyway), doesn't it make sense
to have FILTER_VALIDATE_URL reflect URLs that are actually used?
This means that FILTER_VALIDATE_URL is useless for us since it causes our system to reject customers
that happen to have an underscore in their URL. Unless this bug is fixed, we'll have to
implement a separate solution that will allow the underscore-laden URLs.
This doesn't sound like the best solution to me. Wouldn't you agree?
------------------------------------------------------------------------
[2013-05-30 17:46:40] aharvey@php.net
This is a tricky one. I think the current behaviour is technically correct here,
but I don't particularly want to summarily close this either.
Technically speaking, host names can't include underscores.
http://stackoverflow.com/a/2183140 links to the
various RFCs that define this â
domain names (such as those used in SRV records) can contain underscores, but
host names have a more restrictive character set.
That said, RFC 3986 (which is presumably what a URL validation routine is
ultimately beholden to) is specified more loosely to cover non-DNS name
registries. Hosts are reg-name elements there, which allows percent encoded
characters, hyphens, dots, underscores, tildes, and a range of characters
defined as sub-delims.
Given that underscores do have implementation issues in the wild (IE's cookie
issues, for instance), my inclination is to leave this, as I said at the start,
but I'd like a second opinion.
tl;dr: RFC lawyer material; probably Won't Fix; need a second opinion.
------------------------------------------------------------------------
[2013-05-30 14:59:10] neclimdul at gmail dot com
Description:
------------
FILTER_VALIDATE_URL does not see urls with underscores as valid URLs. Underscores
are however valid and common in urls in the wild.
Test script:
---------------
$url = 'http://foo_bar.example.com';
var_dump(filter_var($url, FILTER_VALIDATE_URL));
Expected result:
----------------
string(26) "http://foo_bar.example.com"
Actual result:
--------------
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64948&edit=1