idna-convert icon indicating copy to clipboard operation
idna-convert copied to clipboard

Error: Prohibited input U+00000081

Open SergeTkach opened this issue 4 years ago • 1 comments

Hi! I am used of idna_convert.class.php @version 0.8.1 2011-12-19 and it works ok. Now I tried to use https://packagist.org/packages/algo26-matthias/idna-convert and I have some error:

CRITICAL - 2021-05-21 23:22:06 --> Prohibited input U+00000081 #0 .../vendor/algo26-matthias/idna-convert/src/NamePrep/NamePrep.php(54): Algo26\IdnaConvert\NamePrep\NamePrep->applyCharacterMaps(Array) #1 .../vendor/algo26-matthias/idna-convert/src/Punycode/ToPunycode.php(51): Algo26\IdnaConvert\NamePrep\NamePrep->do(Array) #2 .../vendor/algo26-matthias/idna-convert/src/ToIdn.php(58): Algo26\IdnaConvert\Punycode\ToPunycode->convert(Array) #3 .../app/Helpers/domain_helper.php(11): Algo26\IdnaConvert\ToIdn->convert('\xC3\x90\xC2\xBC\xC3\x90\xC2\xB0\xC3\x91\xC2\x81\xC3\x91\xC2...') #4 .../app/Controllers/Home.php(111): get_sitename('\xD0\xBC\xD0\xB0\xD1\x81\xD1\x82\xD0\xB5\xD1\x80\xD1\x81\xD0...') #5 .../system/CodeIgniter.php(918): App\Controllers\Home->index() #6 .../system/CodeIgniter.php(404): CodeIgniter\CodeIgniter->runController(Object(App\Controllers\Home)) #7 .../system/CodeIgniter.php(312): CodeIgniter\CodeIgniter->handleRequest(NULL, Object(Config\Cache), false) #8 .../public/index.php(45): CodeIgniter\CodeIgniter->run() #9 {main}

I tried to input cyrillic domain and I found an error then I tried domain from your example nörgler.com. There was error also

To Reproduce

  1. I required https://packagist.org/packages/algo26-matthias/idna-convert to my CodeIgniter 4 project
  2. I created helper app/Helpers/domain_helper.php
  3. I wrote code:
<?php
use Algo26\IdnaConvert\ToIdn;

function get_sitename($domain)
{    
    if (!preg_match("/[a-z.-]+$/", $domain)) {
        $IDN = new ToIdn(2003);
        $input = utf8_encode($domain);
        $domain = $IDN->convert($input);  
    }
    
    return $domain;
}

Expected behavior I would like to transform cyrillic domain to punycode in my form

Finnaly I resolved this problem such a way:

// $input = utf8_encode($domain);
$input = mb_convert_encoding($domain, 'utf-8', mb_detect_encoding($domain));

SergeTkach avatar May 21 '21 21:05 SergeTkach

Sorry, this one got lost in a flood of emails from other GitHub stuff. So basically the problem is described in the documentation, that you'll always need to either provide UTF-8 as input or make sure, your input is ISO-8859-1. That's what PHP is speaking natively. For all other locales, especially Cyrillic ones, you are somewhere in ISO-8859-, which leads to broken input for IDNA Convert.

Your solution is the right one, or at least a working one for your context. For future projects, try using UTF-8 everywhere. This helps to avoid a lot of charset conversion issues.

algo26-matthias avatar Sep 28 '21 17:09 algo26-matthias