Skip to content

Commit

Permalink
Merge branch 'hotfix/1.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
titouanmathis committed Nov 17, 2022
2 parents fbaabe4 + abe0724 commit 002ab1c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
5 changes: 2 additions & 3 deletions src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 28 additions & 0 deletions src/Helpers/Url.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* @link https://github.com/studiometa/twig-toolkit
* @copyright Studio Meta
* @license https://github.com/studiometa/twig-toolkit/blob/master/LICENSE
*/

namespace Studiometa\TwigToolkit\Helpers;

use Twig\Environment;
use Spatie\Url\Url as UrlCore;

/**
* Url manipulation helper.
*
* @author Studio Meta <[email protected]>
* @since 1.3.1
*/
class Url extends UrlCore
{
/**
* @return self
*/
public static function fromString(?string $url)
{
return parent::fromString($url ?? '');
}
}
13 changes: 13 additions & 0 deletions tests/Helpers/UrlTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

use function Spatie\Snapshots\assertMatchesSnapshot;
use Studiometa\TwigToolkit\Helpers\Url;

test('The `Url` class should work with null given as $url', function () {
expect(function () {
Url::fromString(null);
})->not->toThrow('type string, null given');

expect((string)Url::fromString(null))->toBe('');
expect((string)Url::fromString(null)->withHost('fqdn.tld'))->toBe('//fqdn.tld');
});

0 comments on commit 002ab1c

Please sign in to comment.