Skip to content
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
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