Skip to content

Commit

Permalink
Merge pull request #33353 from tufahu/fix-laminas-escaper-type
Browse files Browse the repository at this point in the history
Incompatibility with laminas-escaper (>=2.7.1) has been fixed
  • Loading branch information
Andrii Beziazychnyi authored Jul 30, 2021
2 parents 356a4c9 + 733dec5 commit 057e838
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/internal/Magento/Framework/Escaper.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public function escapeUrl($string)
*/
public function encodeUrlParam($string)
{
return $this->getEscaper()->escapeUrl($string);
return $this->getEscaper()->escapeUrl((string)$string);
}

/**
Expand Down Expand Up @@ -330,7 +330,7 @@ function ($matches) {
*/
public function escapeCss($string)
{
return $this->getEscaper()->escapeCss($string);
return $this->getEscaper()->escapeCss((string)$string);
}

/**
Expand Down
70 changes: 70 additions & 0 deletions lib/internal/Magento/Framework/Test/Unit/EscaperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,76 @@ public function testEscapeUrl(string $data, string $expected): void
$this->assertEquals($expected, $this->escaper->escapeUrl($expected));
}

/**
* @covers \Magento\Framework\Escaper::escapeCss
*
* @param string $data
* @param string $expected
* @return void
*
* @dataProvider escapeCssDataProvider
*/
public function testEscapeCss($data, string $expected): void
{
$this->assertEquals($expected, $this->escaper->escapeCss($data));
}

/**
* @return array
*/
public function escapeCssDataProvider(): array
{
return [
[
'data' => 1,
'expected' => '1',
],
[
'data' => '*%string{foo}%::',
'expected' => '\2A \25 string\7B foo\7D \25 \3A \3A ',
]
];
}

/**
* @covers \Magento\Framework\Escaper::encodeUrlParam
*
* @param string $data
* @param string $expected
* @return void
*
* @dataProvider encodeUrlParamDataProvider
*/
public function testEncodeUrlParam($data, string $expected): void
{
$this->assertEquals($expected, $this->escaper->encodeUrlParam($data));
}

/**
* @return array
*/
public function encodeUrlParamDataProvider(): array
{
return [
[
'data' => "a3==",
'expected' => "a3%3D%3D",
],
[
'data' => "example string",
'expected' => "example%20string",
],
[
'data' => 1,
'expected' => "1",
],
[
'data' => null,
'expected' => "",
]
];
}

/**
* @return array
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/Magento/Framework/Url/RouteParamsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function setRouteParams(array $data, $unsetOldParams = true)
} else {
$this->setRouteParam(
$this->getEscaper()->encodeUrlParam($key),
$this->getEscaper()->encodeUrlParam($value)
$this->getEscaper()->encodeUrlParam((string)$value)
);
}
}
Expand Down

0 comments on commit 057e838

Please sign in to comment.