Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Trim whitespaces in JSON decode helper #603

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Classes/ViewHelpers/Format/Json/DecodeViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public function render()
$json = $this->arguments['json'];
if ($json === null) {
$json = $this->renderChildren();
if ($json !== null) {
$json = trim($json);
}
if (empty($json)) {
return null;
}
Expand Down
28 changes: 28 additions & 0 deletions Tests/Unit/ViewHelpers/Format/Json/DecodeViewHelperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of the "headless" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/

declare(strict_types=1);

namespace FriendsOfTYPO3\Headless\Tests\Unit\ViewHelpers\Format\Json;

use FriendsOfTYPO3\Headless\ViewHelpers\Format\Json\DecodeViewHelper;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

class DecodeViewHelperTest extends UnitTestCase
{
public function testRender(): void
{
$GLOBALS['TYPO3_CONF_VARS']['FE']['debug'] = true;
$decodeViewHelper = new DecodeViewHelper();
$decodeViewHelper->setArguments(['json' => null]);
$decodeViewHelper->setRenderChildrenClosure(function () { return "\n \n"; });
$result = $decodeViewHelper->render();
self::assertNull($result);
}
}