0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-01-03 13:21:51 +00:00

Use idn_to_ascii when available.

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
This commit is contained in:
Edward Z. Yang 2016-03-02 01:35:07 -08:00
parent 913ac6955b
commit aebe1c02a2
2 changed files with 6 additions and 3 deletions

View File

@ -89,11 +89,14 @@ class HTMLPurifier_AttrDef_URI_Host extends HTMLPurifier_AttrDef
return $string; return $string;
} }
// PHP 5.3 and later support this functionality natively
if (function_exists('idn_to_ascii')) {
return idn_to_ascii($string);
// If we have Net_IDNA2 support, we can support IRIs by // If we have Net_IDNA2 support, we can support IRIs by
// punycoding them. (This is the most portable thing to do, // punycoding them. (This is the most portable thing to do,
// since otherwise we have to assume browsers support // since otherwise we have to assume browsers support
} elseif ($config->get('Core.EnableIDNA')) {
if ($config->get('Core.EnableIDNA')) {
$idna = new Net_IDNA2(array('encoding' => 'utf8', 'overlong' => false, 'strict' => true)); $idna = new Net_IDNA2(array('encoding' => 'utf8', 'overlong' => false, 'strict' => true));
// we need to encode each period separately // we need to encode each period separately
$parts = explode('.', $string); $parts = explode('.', $string);

View File

@ -42,7 +42,7 @@ class HTMLPurifier_AttrDef_URI_HostTest extends HTMLPurifier_AttrDefHarness
public function testIDNA() public function testIDNA()
{ {
if (!$GLOBALS['HTMLPurifierTest']['Net_IDNA2']) { if (!$GLOBALS['HTMLPurifierTest']['Net_IDNA2'] && !function_exists("idn_to_ascii")) {
return false; return false;
} }
$this->config->set('Core.EnableIDNA', true); $this->config->set('Core.EnableIDNA', true);