diff --git a/CHANGELOG.md b/CHANGELOG.md index 0480349..2805051 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] -## v1.3.0 +## v1.3.1 (2022-11-17) + +### Fixed + +- Fix `twig_toolkit_url` function throwing an error when used with a `null` value ([#16](https://github.com/studiometa/twig-toolkit/pull/16)) + +## v1.3.0 (2022-11-17) ### Added diff --git a/composer.json b/composer.json index 3cd346d..6879979 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "studiometa/twig-toolkit", - "version": "1.3.0", + "version": "1.3.1", "description": "A set of useful extension and components for Twig.", "license": "MIT", "require": { diff --git a/src/Extension.php b/src/Extension.php index a5ff304..9014ebb 100644 --- a/src/Extension.php +++ b/src/Extension.php @@ -9,15 +9,14 @@ use Studiometa\TwigToolkit\Helpers\Html; use Studiometa\TwigToolkit\Helpers\Template; +use Studiometa\TwigToolkit\Helpers\Url; use Studiometa\TwigToolkit\Node\ElementNode; use Studiometa\TwigToolkit\TokenParser\ElementTokenParser; - use Twig\Extension\AbstractExtension; use Twig\Loader\FilesystemLoader; use Twig\TokenParser\TokenParserInterface; -use Twig\TwigFunction; use Twig\TwigFilter; -use Spatie\Url\Url; +use Twig\TwigFunction; /** * Twig extension class. diff --git a/src/Helpers/Url.php b/src/Helpers/Url.php new file mode 100644 index 0000000..d0f7784 --- /dev/null +++ b/src/Helpers/Url.php @@ -0,0 +1,28 @@ + + * @since 1.3.1 + */ +class Url extends UrlCore +{ + /** + * @return self + */ + public static function fromString(?string $url) + { + return parent::fromString($url ?? ''); + } +} diff --git a/tests/Helpers/UrlTest.php b/tests/Helpers/UrlTest.php new file mode 100644 index 0000000..30f8e1d --- /dev/null +++ b/tests/Helpers/UrlTest.php @@ -0,0 +1,13 @@ +not->toThrow('type string, null given'); + + expect((string)Url::fromString(null))->toBe(''); + expect((string)Url::fromString(null)->withHost('fqdn.tld'))->toBe('//fqdn.tld'); +});