This only applies when DNS hostnames are validated
public setValidateIdn ( boolean $allowed ) | ||
$allowed | boolean | Set allowed to true to validate IDNs, and false to not validate them |
/** * Ensure the IDN check works on ressource files as expected * */ public function testRessourceIDN() { $validator = new Zend_Validate_Hostname(); // Check IDN matching $valuesExpected = array(array(true, array('bürger.com', 'hãllo.com', 'hållo.com')), array(true, array('bÜrger.com', 'hÃllo.com', 'hÅllo.com')), array(false, array('hãllo.lt', 'bürger.lt', 'hãllo.lt'))); foreach ($valuesExpected as $element) { foreach ($element[1] as $input) { $this->assertEquals($element[0], $validator->isValid($input), implode("\n", $validator->getMessages()) . $input); } } // Check no IDN matching $validator->setValidateIdn(false); $valuesExpected = array(array(false, array('bürger.com', 'hãllo.com', 'hållo.com'))); foreach ($valuesExpected as $element) { foreach ($element[1] as $input) { $this->assertEquals($element[0], $validator->isValid($input), implode("\n", $validator->getMessages()) . $input); } } // Check setting no IDN matching via constructor unset($validator); $validator = new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_DNS, false); $valuesExpected = array(array(false, array('bürger.com', 'hãllo.com', 'hållo.com'))); foreach ($valuesExpected as $element) { foreach ($element[1] as $input) { $this->assertEquals($element[0], $validator->isValid($input), implode("\n", $validator->getMessages()) . $input); } } }
</head> <body> <h1>Validate_Hostname POST test</h1> <p>Please use this form to test UTF-8 hostnames. A list of supported Top-Level Domains exists in <tt>Zend_Validate_Hostname</tt> in the <tt>$_registeredTlds</tt> class property. You can enable/disable IDN support by changing the radio button below.</p> <p>Some example valid IDN domains to test include: <em>bürger.de, hãllo.de, hållo.se, bÜrger.de, hÃllo.de, hÅllo.se, höhö.ch</em></p> <p>Some example invalid IDN domains to test include: <em>hãllo.se, bürger.com, hãllo.uk</em></p> <?php if ($_POST['action'] === 'validate') { require_once 'Zend/Validate/Hostname.php'; $characters = strip_tags($_POST['chars']); $validator = new Zend_Validate_Hostname(); $idn = true; if ($_POST['idn'] === "no") { $validator->setValidateIdn(false); $idn = false; } ?> <h2>Entered characters: <?php echo $characters; ?> </h2> <p><?php echo $idn ? 'IDN supported' : 'IDN not supported'; ?> </p> <p>Testing for match in Zend_Validate_Hostname: