algo26-matthias / idna-convert

Pure PHP IDNA Converter
http://idnaconv.net
GNU Lesser General Public License v2.1
66 stars 23 forks source link

domains with idna localpart and "normal" tld can't be encoded #2

Closed herndlm closed 8 years ago

herndlm commented 8 years ago
<?php

require_once(__DIR__ . '/IdnaConvert.php');
use Mso\IdnaConvert\IdnaConvert;

$IDN = new IdnaConvert();
$output = $IDN->encode('knörz.info');
error_log($output);
$output2 = $IDN->decode($output);
error_log($output2);

results in

$ php test.php
xn--knrz-6qa.info
PHP Fatal error:  Uncaught exception 'InvalidArgumentException' with message 'This is not a punycode string' in <dir>/IdnaConvert.php:431
Stack trace:
#0 <dir>/IdnaConvert.php(279): Mso\IdnaConvert\IdnaConvert->_decode('info')
#1 <dir>/test.php(9): Mso\IdnaConvert\IdnaConvert->decode('xn--knrz-6qa.in...')
#2 {main}
  thrown in <dir>/IdnaConvert.php on line 431

because "_decode" also tries to decode the "info" which is not punycode. If I try it with "knörz.knörz" it works. Is this a bug or am I doing something else wrong?

php infos:

$ php --version
PHP 5.4.39 (cli) (built: Mar 19 2015 06:59:35) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
    with Suhosin v0.9.37.1, Copyright (c) 2007-2014, by SektionEins GmbH

update: btw. it works with version 0.9.0

ghost commented 8 years ago

Could you please check, whether it works with the dev branch? Thx in advance!

herndlm commented 8 years ago

Well, I got a bunch of Class x not found errors (maybe I'm using the namespaces wrong) and after fiddling around with includes I got

PHP Parse error:  syntax error, unexpected '+', expecting ',' or ';' in <dir>src/Punycode.php on line x

but fixing this gets me something like

PHP Catchable fatal error:  Argument 1 passed to Mso\IdnaConvert\Punycode::__construct() must be an instance of Mso\IdnaConvert\NamePrepDataInterface, null given, called in <dir>/src/IdnaConvert.php on line x and defined in <dir>/src/Punycode.php on line y
ghost commented 8 years ago

Alright, thanks for trying. I'll look into the whole issue in the next few days and will get back to you as soon as possible.

Stick with 0.9 for the time being.

ghost commented 8 years ago

Hi,

first of all please update your PHP to at least version 5.6.x. A few language constructs used are not available to your old PHP version. If this is not possible, you are unfortunately stuck with version 0.9.x of IdnaConvert.

I looked into the issues and fixed the apparent problems with instantiating the PunyCode class (alongside some minor other issues).

Hope that helps.

herndlm commented 8 years ago

We can't update our PHP atm, but are working on it. Thx for your help. I'll close this for now.