Skip to content

Commit 6b3f81b

Browse files
authored
ENGCOM-5539: fix: escapeUrl("0") should return "0", not "" #23988
2 parents 5265438 + 9efffae commit 6b3f81b

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/internal/Magento/Framework/Escaper.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,16 @@ public function escapeXssInUrl($data)
335335
*/
336336
private function escapeScriptIdentifiers(string $data): string
337337
{
338-
$filteredData = preg_replace('/[\x00-\x1F\x7F\xA0]/u', '', $data) ?: '';
339-
$filteredData = preg_replace(self::$xssFiltrationPattern, ':', $filteredData) ?: '';
338+
$filteredData = preg_replace('/[\x00-\x1F\x7F\xA0]/u', '', $data);
339+
if ($filteredData === false || $filteredData === '') {
340+
return '';
341+
}
342+
343+
$filteredData = preg_replace(self::$xssFiltrationPattern, ':', $filteredData);
344+
if ($filteredData === false) {
345+
return '';
346+
}
347+
340348
if (preg_match(self::$xssFiltrationPattern, $filteredData)) {
341349
$filteredData = $this->escapeScriptIdentifiers($filteredData);
342350
}

lib/internal/Magento/Framework/Test/Unit/EscaperTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ public function testEscapeXssInUrl($input, $expected)
343343
public function escapeDataProvider()
344344
{
345345
return [
346+
[
347+
'0',
348+
'0',
349+
],
346350
[
347351
'javascript%3Aalert%28String.fromCharCode%280x78%29%2BString.'
348352
. 'fromCharCode%280x73%29%2BString.fromCharCode%280x73%29%29',

0 commit comments

Comments
 (0)