From b009e3b8ad4cdd8f54c08564672846e166d96c01 Mon Sep 17 00:00:00 2001 From: ignace nyamagana butera Date: Thu, 23 Nov 2023 22:11:55 +0100 Subject: [PATCH] Prepare 7.4.0 release --- CHANGELOG.md | 2 +- Uri.php | 37 +++++++++++++++++++------------------ 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0defd223..4aab23e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All Notable changes to `League\Uri` will be documented in this file -## Next - TBD +## [7.4.0](https://github.com/thephpleague/uri/compare/7.3.0...7.4.0) - 2023-09-09 ### Added diff --git a/Uri.php b/Uri.php index 69fe0dce..bf06459c 100644 --- a/Uri.php +++ b/Uri.php @@ -521,29 +521,30 @@ public static function fromData(string $data, string $mimetype = '', string $par default => throw new SyntaxError('Invalid mimeType, `'.$mimetype.'`.'), }; - if ('' != $parameters) { - if (str_starts_with($parameters, ';')) { - $parameters = substr($parameters, 1); - } - - $validateParameter = function (string $parameter): bool { - $properties = explode('=', $parameter); + if ('' === $parameters) { + return self::fromComponents([ + 'scheme' => 'data', + 'path' => self::formatDataPath($mimetype.','.rawurlencode($data)), + ]); + } - return 2 != count($properties) || 'base64' === strtolower($properties[0]); - }; + $isInvalidParameter = static function (string $parameter): bool { + $properties = explode('=', $parameter); - $params = array_filter(explode(';', $parameters)); - if ([] !== array_filter($params, $validateParameter(...))) { - throw new SyntaxError(sprintf('Invalid mediatype parameters, `%s`.', $parameters)); - } + return 2 !== count($properties) || 'base64' === strtolower($properties[0]); + }; - $parameters = ';'.$parameters; + if (str_starts_with($parameters, ';')) { + $parameters = substr($parameters, 1); } - return self::fromComponents([ - 'scheme' => 'data', - 'path' => self::formatDataPath($mimetype.$parameters.','.rawurlencode($data)), - ]); + return match ([]) { + array_filter(explode(';', $parameters), $isInvalidParameter) => self::fromComponents([ + 'scheme' => 'data', + 'path' => self::formatDataPath($mimetype.';'.$parameters.','.rawurlencode($data)), + ]), + default => throw new SyntaxError(sprintf('Invalid mediatype parameters, `%s`.', $parameters)) + }; } /**