ZF-84: Zend_Filter::isHostname not allow a hostname that has one character part like "d.hatena.ne.jp" (TRAC-130)


Zend_Filter::isHostname returns false, When it called with a hostname that has one character part. ex) "d.hatena.ne.jp", "a.hatena.ne.jp"

The reason is following regular expression code.

     // check input against domain name schema

- $status = @preg_match('/^(?:[^\W_](?:[^\W_]|-){0,61}[^\W_].)+[a-zA-Z]{2,6}.?$/', $value);

I changed like this, that returns true by calling with a hostname with one character part.

     // check input against domain name schema

+ $status = @preg_match('/^(?:[^\W_]((?:[^\W_]|-){0,61}[^\W_])?.)+[a-zA-Z]{2,6}.?$/', $value);

But I don't know it's valid for RFCs about URI. I think this fix is not so good.


I have been looking for the RFC which specifies the hostname requirements and cannot find any restriction on the number of characters as part of a domain name, does anyone know if there is a restriction or can this fixed be applied?

Well according to RFC2181:

{quote} The DNS itself places only one restriction on the particular labels that can be used to identify resource records. That one restriction relates to the length of the label and the full name. The length of any one label is limited to between 1 and 63 octets. A full domain name is limited to 255 octets (including the separators). {quote}

Based on that logic the fix looks valid.

This is bothering me as well, I cant use Zend_Feed due to it using the hostname validation from this. Are there any plans to impliment this patch? This patch seems to fix the problems i have as well.

Changing fix version to 0.9.0.

I won't promise this issue is fixed by the patch I committed, but it is an improvement. Unless I hear otherwise from the community, I consider this issue "resolved" for the moment.

Please provide unit tests to at least indicate the effects of the change.

Also, please replace tab characters for indent with 4 spaces, per the coding standards.

The isHostname() implementation needs to be rewritten, in my opinion. If someone could write a good test suite, I'd be happy to have a look at it.

moving to Zend_Validate component b/c Zend_Filter static methods are deprecated as of 0.8.0.

Fixed with revision 3429, d.hatena.ne.jp has been added in the unit test and it passes validation.

Bookkeeping. Closing old issues and assigning them to the person who ultimately resolved the issue.