update new IdnaConvert class with needed fixes in them

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2016-06-19 20:15:33 +02:00
parent 5789e9a8a4
commit b22e70804b
2 changed files with 34 additions and 25 deletions

View File

@@ -54,12 +54,10 @@ namespace Mso\IdnaConvert;
class IdnaConvert {
const Version = '1.0.2';
const Version = '1.1.0';
const SubVersion = 'main';
// Internal settings, do not touch!
const PunycodePrefix = 'xn--';
protected $encoding = 'utf8'; // Default input charset is UTF-8
protected $strictMode = false; // Behave strict or not
protected $idnVersion = '2008'; // Can be either 2003 (old) or 2008 (default)
@@ -203,21 +201,17 @@ class IdnaConvert {
list ($email_pref, $input) = explode('@', $input, 2);
$arr = explode('.', $input);
foreach ($arr as $k => $v) {
if (preg_match('!^' . preg_quote(self::PunycodePrefix, '!') . '!', $v)) {
$conv = $punyCode->decode($v);
if ($conv) {
$arr[$k] = $conv;
}
$conv = $punyCode->decode($v);
if ($conv) {
$arr[$k] = $conv;
}
}
$input = join('.', $arr);
$arr = explode('.', $email_pref);
foreach ($arr as $k => $v) {
if (preg_match('!^' . preg_quote(self::PunycodePrefix, '!') . '!', $v)) {
$conv = $punyCode->decode($v);
if ($conv) {
$arr[$k] = $conv;
}
$conv = $punyCode->decode($v);
if ($conv) {
$arr[$k] = $conv;
}
}
$email_pref = join('.', $arr);
@@ -248,7 +242,9 @@ class IdnaConvert {
$arr = explode('.', $input);
foreach ($arr as $k => $v) {
$conv = $punyCode->decode($v);
$arr[$k] = ($conv) ? $conv : $v;
if ($conv) {
$arr[$k] = $conv;
}
}
$return = join('.', $arr);
}