Skip to content

Commit 1a8f234

Browse files
committed
Fixes for escapeJs method
1 parent 92002c1 commit 1a8f234

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/internal/Magento/Framework/Escaper.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,12 @@ public function encodeUrlParam($string)
303303
*/
304304
public function escapeJs($string)
305305
{
306-
if (!is_string($string) && !is_array($string)) {
306+
if (!is_string($string)) {
307307
// In PHP > 8, preg_replace_callback throws an error if the 3rd param type is incorrect.
308308
// This check emulates an old behavior.
309-
return $string;
309+
$string = (string) $string;
310310
}
311+
311312
if ($string === '' || ctype_digit($string)) {
312313
return $string;
313314
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ public function escapeJsDataProvider()
137137
{
138138
return [
139139
'zero length string' => ['', ''],
140+
'null as string' => [null, ''],
141+
'Magento\Framework\Phrase as string' => [__('test'), 'test'],
140142
'only digits' => ['123', '123'],
141143
'<' => ['<', '\u003C'],
142144
'>' => ['>', '\\u003E'],

0 commit comments

Comments
 (0)