ensure the replacing of the stdsubdomain url on update is encoded correctly

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2019-01-11 08:55:55 +01:00
parent 7841eebf08
commit 9a906427e7
2 changed files with 18 additions and 9 deletions

View File

@@ -56,7 +56,16 @@ class IdnaWrapper
public function encode($to_encode) public function encode($to_encode)
{ {
$to_encode = $this->isUtf8($to_encode) ? $to_encode : utf8_encode($to_encode); $to_encode = $this->isUtf8($to_encode) ? $to_encode : utf8_encode($to_encode);
return $this->idna_converter->encode($to_encode); try {
return $this->idna_converter->encode($to_encode);
} catch (\InvalidArgumentException $iae) {
// dirty hack because Mso\IdnaConvert does not specify error-numbers
// see https://github.com/phlylabs/idna-convert/issues/11
if (strtolower($iae->getMessage()) == 'this is already a punycode string') {
return $to_encode;
}
throw $iae;
}
} }
/** /**

View File

@@ -225,22 +225,22 @@ class Store
$idna_convert = new \Froxlor\Idna\IdnaWrapper(); $idna_convert = new \Froxlor\Idna\IdnaWrapper();
$newfieldvalue = $idna_convert->encode($newfieldvalue); $newfieldvalue = $idna_convert->encode($newfieldvalue);
if (($fielddata['varname'] == 'hostname' && Settings::Get('system.stdsubdomain') == '') || $fielddata['varname'] == 'stdsubdomain') if (($fielddata['varname'] == 'hostname' && Settings::Get('system.stdsubdomain') == '') || $fielddata['varname'] == 'stdsubdomain') {
{
if ($fielddata['varname'] == 'stdsubdomain' && $newfieldvalue == '') { if ($fielddata['varname'] == 'stdsubdomain' && $newfieldvalue == '') {
// clear field, reset stdsubdomain to system-hostname // clear field, reset stdsubdomain to system-hostname
$oldhost = Settings::Get('system.stdsubdomain'); $oldhost = $idna_convert->encode(Settings::Get('system.stdsubdomain'));
$newhost = Settings::Get('system.hostname'); $newhost = $idna_convert->encode(Settings::Get('system.hostname'));
} elseif ($fielddata['varname'] == 'stdsubdomain' && Settings::Get('system.stdsubdomain') == '') { } elseif ($fielddata['varname'] == 'stdsubdomain' && Settings::Get('system.stdsubdomain') == '') {
// former std-subdomain was system-hostname // former std-subdomain was system-hostname
$oldhost = Settings::Get('system.hostname'); $oldhost = $idna_convert->encode(Settings::Get('system.hostname'));
$newhost = Settings::Get('system.stdsubdomain'); $newhost = $newfieldvalue;
} elseif ($fielddata['varname'] == 'stdsubdomain') { } elseif ($fielddata['varname'] == 'stdsubdomain') {
// std-subdomain just changed // std-subdomain just changed
$oldhost = Settings::Get('system.stdsubdomain'); $oldhost = $idna_convert->encode(Settings::Get('system.stdsubdomain'));
$newhost = $newfieldvalue; $newhost = $newfieldvalue;
} elseif ($fielddata['varname'] == 'hostname' && Settings::Get('system.stdsubdomain') == '') { } elseif ($fielddata['varname'] == 'hostname' && Settings::Get('system.stdsubdomain') == '') {
$oldhost = Settings::Get('system.hostname'); // system-hostname has changed and no system-stdsubdomain is not set
$oldhost = $idna_convert->encode(Settings::Get('system.hostname'));
$newhost = $newfieldvalue; $newhost = $newfieldvalue;
} }