Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX] Prevent double escaping for src attribute in ScriptViewHelper
This patch prevents double escaping of the src attribute by unescaping the value before handover to the AssetCollector->addJavaScript() function. Resolves: #92284 Releases: master, 10.4 Change-Id: Ia9bb22e176f8a58a8bba642599546d13aa4855d2 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/66294 Tested-by: TYPO3com <noreply@typo3.com> Tested-by: Daniel Goerz <daniel.goerz@posteo.de> Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
- Loading branch information
Showing
3 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
typo3/sysext/fluid/Tests/Unit/ViewHelpers/Asset/ScriptViewHelperTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format; | ||
|
||
use Prophecy\Argument; | ||
use TYPO3\CMS\Core\Page\AssetCollector; | ||
use TYPO3\CMS\Fluid\ViewHelpers\Asset\ScriptViewHelper; | ||
use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase; | ||
|
||
class ScriptViewHelperTest extends ViewHelperBaseTestcase | ||
{ | ||
/** | ||
* @var ScriptViewHelper | ||
*/ | ||
protected $viewHelper; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->viewHelper = new ScriptViewHelper(); | ||
$this->injectDependenciesIntoViewHelper($this->viewHelper); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function valueDataProvider(): array | ||
{ | ||
return [ | ||
'fileadmin reference' => ['fileadmin/JavaScript/foo.js'], | ||
'EXT: reference' => ['EXT:core/Resources/Public/JavaScript/foo.js'], | ||
'external reference' => ['https://typo3.com/foo.js'], | ||
'external reference with 1 parameter' => ['https://typo3.com/foo.js?foo=bar'], | ||
'external reference with 2 parameters' => ['https://typo3.com/foo.js?foo=bar&bar=baz'], | ||
]; | ||
} | ||
|
||
/** | ||
* @param string $src | ||
* @test | ||
* @dataProvider valueDataProvider | ||
*/ | ||
public function render(string $src): void | ||
{ | ||
$assetCollector = $this->prophesize(AssetCollector::class); | ||
$assetCollector | ||
->addJavaScript('test', $src, Argument::any(), Argument::any()) | ||
->shouldBeCalled(); | ||
$this->viewHelper->injectAssetCollector($assetCollector->reveal()); | ||
$this->setArgumentsUnderTest($this->viewHelper, [ | ||
'identifier' => 'test', | ||
'src' => $src, | ||
]); | ||
$this->viewHelper->initializeArgumentsAndRender(); | ||
} | ||
} |