Skip to content

Commit

Permalink
Improve string util test
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed May 19, 2021
1 parent a5586c0 commit 3bd6984
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions core-bundle/tests/Contao/StringUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use Contao\CoreBundle\Security\Authentication\Token\TokenChecker;
use Contao\CoreBundle\Tests\TestCase;
use Contao\Input;
use Contao\StringUtil;
use Contao\System;
use Psr\Log\NullLogger;
Expand Down Expand Up @@ -155,6 +156,14 @@ public function trimsplitProvider(): \Generator
public function testGetsRawDecodedValues(string $source, string $expected, bool $removeInsertTags = false): void
{
$this->assertSame($expected, StringUtil::getRawDecodedValue($source, $removeInsertTags));

Input::setGet('value', $expected);
$inputEncoded = Input::get('value');
Input::setGet('value', null);

// Test input encoding round trip
$this->assertSame($expected, StringUtil::getRawDecodedValue($inputEncoded, true));
$this->assertSame($expected, StringUtil::getRawDecodedValue($inputEncoded, false));
}

public function getRawDecodedValueProvider(): \Generator
Expand All @@ -178,6 +187,12 @@ public function getRawDecodedValueProvider(): \Generator
public function testGetsRawDecodedValuesFromHtml(string $source, string $expected, bool $removeInsertTags = false): void
{
$this->assertSame($expected, StringUtil::getRawDecodedValueFromHtml($source, $removeInsertTags));

Input::setPost('value', str_replace(['{{', '}}'], ['[{]', '[}]'], $source));
$inputXssStripped = str_replace(['{{', '}}'], ['{{', '}}'], Input::postHtml('value', true));
Input::setPost('value', null);

$this->assertSame($expected, StringUtil::getRawDecodedValueFromHtml($inputXssStripped, $removeInsertTags));
}

public function getRawDecodedValueFromHtmlProvider(): \Generator
Expand Down

0 comments on commit 3bd6984

Please sign in to comment.