algo26-matthias / idna-convert

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

IdnaConvert::decode() fails to convert simple domain name #6

Closed cerlestes closed 8 years ago

cerlestes commented 8 years ago
$converter = new IdnaConvert();
$converter->decode('xn--zcaj8cya.bar.baz');

The above code will fail with the following exception: This is not a punycode string

This is because it's pushing every domain part into Punycode::decode(), which will raise the aforementioned exception when the provided string (bar in this case) is not punycoded.

Imho parse_url() shouldn't be used within the decode() method. There should be a separate decodeUri() method, to reflect how encoding is handled. And of course the exception must be handled within the IdnaConvert class, i.e. just ignoring it and using the input string.

cerlestes commented 8 years ago

I've created two pull requests now. #8 is backwards-compatible and just adds more checks to the current code. #7 is a breaking change, that modifies the public API (one constant removed, one exception removed) and removes unnecessary (and bad-quality) code.