13
13
use Magento \Framework \DataObject ;
14
14
use Magento \Framework \Serialize \Serializer \Json ;
15
15
use Magento \Framework \View \Element \Block \ArgumentInterface ;
16
+ use Magento \Framework \Escaper ;
16
17
17
18
/**
18
19
* Product breadcrumbs view model.
@@ -36,21 +37,29 @@ class Breadcrumbs extends DataObject implements ArgumentInterface
36
37
*/
37
38
private $ json ;
38
39
40
+ /**
41
+ * @var Escaper
42
+ */
43
+ private $ escaper ;
44
+
39
45
/**
40
46
* @param Data $catalogData
41
47
* @param ScopeConfigInterface $scopeConfig
42
- * @param Json $json
48
+ * @param Json|null $json
49
+ * @param Escaper|null $escaper
43
50
*/
44
51
public function __construct (
45
52
Data $ catalogData ,
46
53
ScopeConfigInterface $ scopeConfig ,
47
- Json $ json = null
54
+ Json $ json = null ,
55
+ Escaper $ escaper = null
48
56
) {
49
57
parent ::__construct ();
50
58
51
59
$ this ->catalogData = $ catalogData ;
52
60
$ this ->scopeConfig = $ scopeConfig ;
53
61
$ this ->json = $ json ?: ObjectManager::getInstance ()->get (Json::class);
62
+ $ this ->escaper = $ escaper ?: ObjectManager::getInstance ()->get (Escaper::class);
54
63
}
55
64
56
65
/**
@@ -98,12 +107,14 @@ public function getProductName(): string
98
107
*/
99
108
public function getJsonConfiguration ()
100
109
{
101
- return $ this ->json ->serialize ([
102
- 'breadcrumbs ' => [
103
- 'categoryUrlSuffix ' => $ this ->getCategoryUrlSuffix (),
104
- 'userCategoryPathInUrl ' => (int )$ this ->isCategoryUsedInProductUrl (),
105
- 'product ' => $ this ->getProductName ()
110
+ return $ this ->json ->serialize (
111
+ [
112
+ 'breadcrumbs ' => [
113
+ 'categoryUrlSuffix ' => $ this ->escaper ->escapeHtml ($ this ->getCategoryUrlSuffix ()),
114
+ 'userCategoryPathInUrl ' => (int )$ this ->isCategoryUsedInProductUrl (),
115
+ 'product ' => $ this ->escaper ->escapeHtml ($ this ->escaper ->escapeJs ($ this ->getProductName ()))
116
+ ]
106
117
]
107
- ] );
118
+ );
108
119
}
109
120
}
0 commit comments