zendframework / zf1

This project reached its end-of-life on 2016-09-28. Contains conversion of ZF1 subversion repo to git, from version 15234 forward, and only containing master and release-1.12 branches and 1.12 tags.
https://framework.zend.com/blog/2016-06-28-zf1-eol.html
BSD 3-Clause "New" or "Revised" License
358 stars 795 forks source link

Zend_Validate_Hostname does not validate NTP hostnames starting with '0' character #612

Closed thaxyh closed 9 years ago

thaxyh commented 9 years ago

Hello, I have a problem with validating NTP hostnames despite using of ALLOW_ALL setting. I use PHP 5.6.6 and ZendFramework 1.12.9, but the problem also applies to the latest version of ZF1.

$v = new Zend_Validate_Hostname([ 'allow' => Zend_Validate_Hostname::ALLOW_ALL ]);
var_dump($v->isValid('1.pool.ntp.org')); // bool(true)
var_dump($v->isValid('0.pool.ntp.org')); // bool(false)

Usage of empty() function (Zend/Validate/Hostname.php:1462 for ZF1.12.15) causes this issue, because empty(0) returns false.

A simple change might solve it:

1462c1462
<                         if (empty($domainPart)) {

---
>                         if (empty($domainPart) && $domainPart != '0') {
froschdesign commented 9 years ago

@mhujer Can you check this?

thaxyh commented 9 years ago

Works for me;)

thaxyh commented 9 years ago

Any chance to add it to the sources?

froschdesign commented 9 years ago

Any chance to add it to the sources?

…with the next release.

thaxyh commented 9 years ago

Great! Thank you:)

mhujer commented 9 years ago

Created a PR with the fix and test: #615

froschdesign commented 9 years ago

@mhujer Thanks!

glensc commented 8 years ago

why not use $domainPart !== '' to match empty string?