Skip to content

Commit

Permalink
Prepare 7.4.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Nov 24, 2023
1 parent 13108c5 commit b009e3b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
37 changes: 19 additions & 18 deletions Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
};
}

/**
Expand Down

0 comments on commit b009e3b

Please sign in to comment.