diff options
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Accounts/AccountManager.php | 3 | ||||
-rw-r--r-- | lib/private/FullTextSearch/Model/IndexDocument.php | 2 | ||||
-rw-r--r-- | lib/private/Installer.php | 15 | ||||
-rw-r--r-- | lib/private/L10N/L10N.php | 30 | ||||
-rw-r--r-- | lib/private/L10N/L10NString.php | 39 | ||||
-rw-r--r-- | lib/private/Share20/Manager.php | 4 |
6 files changed, 50 insertions, 43 deletions
diff --git a/lib/private/Accounts/AccountManager.php b/lib/private/Accounts/AccountManager.php index eff025e511e..53792c70d27 100644 --- a/lib/private/Accounts/AccountManager.php +++ b/lib/private/Accounts/AccountManager.php @@ -153,6 +153,9 @@ class AccountManager implements IAccountManager { $updated = true; if (isset($data[self::PROPERTY_PHONE]) && $data[self::PROPERTY_PHONE]['value'] !== '') { + // Sanitize null value. + $data[self::PROPERTY_PHONE]['value'] = $data[self::PROPERTY_PHONE]['value'] ?? ''; + try { $data[self::PROPERTY_PHONE]['value'] = $this->parsePhoneNumber($data[self::PROPERTY_PHONE]['value']); } catch (\InvalidArgumentException $e) { diff --git a/lib/private/FullTextSearch/Model/IndexDocument.php b/lib/private/FullTextSearch/Model/IndexDocument.php index 252aa66395a..44bd7a23a1c 100644 --- a/lib/private/FullTextSearch/Model/IndexDocument.php +++ b/lib/private/FullTextSearch/Model/IndexDocument.php @@ -722,7 +722,7 @@ class IndexDocument implements IIndexDocument, JsonSerializable { * @param string $excerpt * @return string */ - final private function cleanExcerpt(string $excerpt): string { + private function cleanExcerpt(string $excerpt): string { $excerpt = str_replace("\\n", ' ', $excerpt); $excerpt = str_replace("\\r", ' ', $excerpt); $excerpt = str_replace("\\t", ' ', $excerpt); diff --git a/lib/private/Installer.php b/lib/private/Installer.php index fdf9af7446b..da3cef7d1e7 100644 --- a/lib/private/Installer.php +++ b/lib/private/Installer.php @@ -307,7 +307,10 @@ class Installer { // Check if the signature actually matches the downloaded content $certificate = openssl_get_publickey($app['certificate']); $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); - openssl_free_key($certificate); + // PHP 8+ deprecates openssl_free_key and automatically destroys the key instance when it goes out of scope + if ((PHP_VERSION_ID < 80000)) { + openssl_free_key($certificate); + } if ($verified === true) { // Seems to match, let's proceed @@ -339,9 +342,13 @@ class Installer { } // Check if appinfo/info.xml has the same app ID as well - $loadEntities = libxml_disable_entity_loader(false); - $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); - libxml_disable_entity_loader($loadEntities); + if ((PHP_VERSION_ID < 80000)) { + $loadEntities = libxml_disable_entity_loader(false); + $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); + libxml_disable_entity_loader($loadEntities); + } else { + $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); + } if ((string)$xml->id !== $appId) { throw new \Exception( sprintf( diff --git a/lib/private/L10N/L10N.php b/lib/private/L10N/L10N.php index 3b32ec2827f..72f124f7754 100644 --- a/lib/private/L10N/L10N.php +++ b/lib/private/L10N/L10N.php @@ -32,7 +32,7 @@ namespace OC\L10N; use OCP\IL10N; use OCP\L10N\IFactory; use Punic\Calendar; -use Symfony\Component\Translation\PluralizationRules; +use Symfony\Component\Translation\IdentityTranslator; class L10N implements IL10N { @@ -48,11 +48,8 @@ class L10N implements IL10N { /** @var string Locale of this object */ protected $locale; - /** @var string Plural forms (string) */ - private $pluralFormString = 'nplurals=2; plural=(n != 1);'; - - /** @var string Plural forms (function) */ - private $pluralFormFunction = null; + /** @var IdentityTranslator */ + private $identityTranslator; /** @var string[] */ private $translations = []; @@ -214,20 +211,16 @@ class L10N implements IL10N { } /** - * Returnsed function accepts the argument $n - * - * Called by \OC_L10N_String - * @return \Closure the plural form function + * @internal + * @return IdentityTranslator */ - public function getPluralFormFunction(): \Closure { - if (\is_null($this->pluralFormFunction)) { - $lang = $this->getLanguageCode(); - $this->pluralFormFunction = function ($n) use ($lang) { - return PluralizationRules::get($n, $lang); - }; + public function getIdentityTranslator(): IdentityTranslator { + if (\is_null($this->identityTranslator)) { + $this->identityTranslator = new IdentityTranslator(); + $this->identityTranslator->setLocale($this->getLocaleCode()); } - return $this->pluralFormFunction; + return $this->identityTranslator; } /** @@ -242,9 +235,6 @@ class L10N implements IL10N { return false; } - if (!empty($json['pluralForm'])) { - $this->pluralFormString = $json['pluralForm']; - } $this->translations = array_merge($this->translations, $json['translations']); return true; } diff --git a/lib/private/L10N/L10NString.php b/lib/private/L10N/L10NString.php index a82228189b6..9d219ea1772 100644 --- a/lib/private/L10N/L10NString.php +++ b/lib/private/L10N/L10NString.php @@ -32,7 +32,7 @@ namespace OC\L10N; class L10NString implements \JsonSerializable { - /** @var \OC\L10N\L10N */ + /** @var L10N */ protected $l10n; /** @var string */ @@ -45,37 +45,44 @@ class L10NString implements \JsonSerializable { protected $count; /** - * @param \OC\L10N\L10N $l10n + * @param L10N $l10n * @param string|string[] $text * @param array $parameters * @param int $count */ - public function __construct(\OC\L10N\L10N $l10n, $text, $parameters, $count = 1) { + public function __construct(L10N $l10n, $text, array $parameters, int $count = 1) { $this->l10n = $l10n; $this->text = $text; $this->parameters = $parameters; $this->count = $count; } - /** - * @return string - */ - public function __toString() { + public function __toString(): string { $translations = $this->l10n->getTranslations(); + $identityTranslator = $this->l10n->getIdentityTranslator(); - $text = $this->text; + // Use the indexed version as per \Symfony\Contracts\Translation\TranslatorInterface + $identity = $this->text; if (array_key_exists($this->text, $translations)) { - if (is_array($translations[$this->text])) { - $fn = $this->l10n->getPluralFormFunction(); - $id = $fn($this->count); - $text = $translations[$this->text][$id]; - } else { - $text = $translations[$this->text]; + $identity = $translations[$this->text]; + } + + if (is_array($identity)) { + $pipeCheck = implode('', $identity); + if (strpos($pipeCheck, '|') !== false) { + return 'Can not use pipe character in translations'; } + + $identity = implode('|', $identity); + } elseif (strpos($identity, '|') !== false) { + return 'Can not use pipe character in translations'; } - // Replace %n first (won't interfere with vsprintf) - $text = str_replace('%n', (string)$this->count, $text); + $identity = str_replace('%n', '%count%', $identity); + + // $count as %count% as per \Symfony\Contracts\Translation\TranslatorInterface + $text = $identityTranslator->trans($identity, ['%count%' => $this->count]); + return vsprintf($text, $this->parameters); } diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 7211a4eb1e8..00020c3a8f6 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -441,7 +441,7 @@ class Manager implements IManager { $date->setTime(0, 0, 0); $date->add(new \DateInterval('P' . $defaultExpireDays . 'D')); if ($date < $expirationDate) { - $message = $this->l->t('Can’t set expiration date more than %s days in the future', [$defaultExpireDays]); + $message = $this->l->n('Can’t set expiration date more than %n day in the future', 'Can’t set expiration date more than %n days in the future', $defaultExpireDays); throw new GenericShareException($message, $message, 404); } } @@ -517,7 +517,7 @@ class Manager implements IManager { $date->setTime(0, 0, 0); $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D')); if ($date < $expirationDate) { - $message = $this->l->t('Can’t set expiration date more than %s days in the future', [$this->shareApiLinkDefaultExpireDays()]); + $message = $this->l->n('Can’t set expiration date more than %n day in the future', 'Can’t set expiration date more than %n days in the future', $this->shareApiLinkDefaultExpireDays()); throw new GenericShareException($message, $message, 404); } } |