File tree Expand file tree Collapse file tree 7 files changed +102
-20
lines changed
Catalog/view/adminhtml/web/js
dev/tests/integration/testsuite/Magento
UrlRewrite/Block/Catalog/Category Expand file tree Collapse file tree 7 files changed +102
-20
lines changed Original file line number Diff line number Diff line change 5
5
6
6
define ( [
7
7
'jquery' ,
8
+ 'mageUtils' ,
8
9
'jquery/ui' ,
9
10
'jquery/jstree/jquery.jstree'
10
- ] , function ( $ ) {
11
+ ] , function ( $ , utils ) {
11
12
'use strict' ;
12
13
13
14
$ . widget ( 'mage.categoryTree' , {
@@ -90,7 +91,7 @@ define([
90
91
}
91
92
result = {
92
93
data : {
93
- title : node . name + ' (' + node [ 'product_count' ] + ')'
94
+ title : utils . unescape ( node . name ) + ' (' + node [ 'product_count' ] + ')'
94
95
} ,
95
96
attr : {
96
97
'class' : node . cls + ( ! ! node . disabled ? ' disabled' : '' ) //eslint-disable-line no-extra-boolean-cast
Original file line number Diff line number Diff line change 3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \UrlRewrite \Block \Catalog \Category ;
7
8
8
9
use Magento \Catalog \Api \CategoryRepositoryInterface ;
Original file line number Diff line number Diff line change 8
8
9
9
/** @var \Magento\UrlRewrite\Block\Catalog\Category\Tree $block */
10
10
?>
11
- <fieldset class="admin__fieldset" data-ui-id="category-selector">
12
- <legend class="admin__legend"><span><?= $ block ->escapeHtml (__ ('Select Category ' )) ?> </span></legend>
13
- <div class="content content-category-tree">
14
- <input type="hidden" name="categories" id="product_categories" value="" />
15
- <?php if ($ block ->getRoot ()): ?>
16
- <div data-mage-init='<?php /* @noEscape */ echo $ this ->helper ('Magento\Framework\Json\Helper\Data ' )->jsonEncode (
17
- [
18
- 'categoryTree ' => [
19
- 'data ' => $ block ->getTreeArray (),
20
- 'url ' => $ block ->escapeUrl ($ block ->getLoadTreeUrl ()),
21
- ],
22
- ]
23
- ); ?> ' class="jstree-default"></div>
24
- <?php endif ; ?>
25
- </div>
26
- </fieldset>
11
+ <fieldset class="admin__fieldset" data-ui-id="category-selector">
12
+ <legend class="admin__legend"><span><?= $ block ->escapeHtml (__ ('Select Category ' )) ?> </span></legend>
13
+ <div class="content content-category-tree">
14
+ <input type="hidden" name="categories" id="product_categories" value=""/>
15
+ <?php if ($ block ->getRoot ()): ?>
16
+ <div class="jstree-default"></div>
17
+ <?php endif ; ?>
18
+ </div>
19
+ </fieldset>
20
+ <?php if ($ block ->getRoot ()): ?>
21
+ <script type="text/x-magento-init">
22
+ {
23
+ ".jstree-default": {
24
+ "categoryTree": {
25
+ "data": <?php /* @noEscape */
26
+ echo $ this ->helper ('Magento\Framework\Json\Helper\Data ' )->jsonEncode ($ block ->getTreeArray ()); ?> ,
27
+ "url": "<?php /* @noEscape */
28
+ echo $ block ->escapeUrl ($ block ->getLoadTreeUrl ()); ?> "
29
+ }
30
+ }
31
+ }
32
+
33
+ </script>
34
+ <?php endif ; ?>
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ declare (strict_types=1 );
7
+
8
+ /** @var $category \Magento\Catalog\Model\Category */
9
+ $ objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
10
+
11
+ $ categoryFirst = $ objectManager ->create (\Magento \Catalog \Model \Category::class);
12
+ $ categoryFirst ->setName ('Category 1 ' )
13
+ ->setPath ('1/2 ' )
14
+ ->setLevel (2 )
15
+ ->setAvailableSortBy ('name ' )
16
+ ->setDefaultSortBy ('name ' )
17
+ ->setIsActive (true )
18
+ ->setPosition (1 )
19
+ ->save ();
20
+
21
+ // products from this fixture were moved to indexer_catalog_products.php
22
+ $ categorySecond = $ objectManager ->create (\Magento \Catalog \Model \Category::class);
23
+ $ categorySecond ->setName ('"Category 6" ' )
24
+ ->setPath ($ categoryFirst ->getPath ())
25
+ ->setLevel (3 )
26
+ ->setAvailableSortBy ('name ' )
27
+ ->setDefaultSortBy ('name ' )
28
+ ->setIsActive (true )
29
+ ->setPosition (1 )
30
+ ->save ();
Original file line number Diff line number Diff line change 3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \UrlRewrite \Block \Catalog \Category ;
7
8
8
9
/**
@@ -56,7 +57,27 @@ public function testGetTreeArrayApostropheReplaced()
56
57
$ tree = $ this ->_treeBlock ->getTreeArray ();
57
58
58
59
$ this ->assertNotContains ('\'' , $ tree ['children ' ][0 ]['children ' ][0 ]['children ' ][0 ]['name ' ]);
59
- $ this ->assertEquals (''Category 6' ' , $ tree ['children ' ][0 ]['children ' ][0 ]['children ' ][0 ]['name ' ]);
60
+ $ this ->assertEquals (
61
+ ''Category 6' ' ,
62
+ $ tree ['children ' ][0 ]['children ' ][0 ]['children ' ][0 ]['name ' ]
63
+ );
64
+ }
65
+
66
+ /**
67
+ * Test that the getTreeArray() method scrubs single quotes and apostrophes from names
68
+ *
69
+ * @magentoAppIsolation enabled
70
+ * @magentoDataFixture Magento/Catalog/_files/catalog_category_with_doublequotes.php
71
+ */
72
+ public function testGetTreeArrayDoubleQuotesReplaced ()
73
+ {
74
+ $ tree = $ this ->_treeBlock ->getTreeArray ();
75
+
76
+ $ this ->assertNotContains ('\" ' , $ tree ['children ' ][0 ]['children ' ][0 ]['children ' ][0 ]['name ' ]);
77
+ $ this ->assertEquals (
78
+ '"Category 6" ' ,
79
+ $ tree ['children ' ][0 ]['children ' ][0 ]['children ' ][0 ]['name ' ]
80
+ );
60
81
}
61
82
62
83
/**
Original file line number Diff line number Diff line change @@ -242,6 +242,26 @@ define([
242
242
return data ;
243
243
} ,
244
244
245
+ /**
246
+ * Replaces symbol codes with their unescaped counterparts.
247
+ *
248
+ * @param {String } data
249
+ *
250
+ * @returns {String }
251
+ */
252
+ unescape : function ( data ) {
253
+ var unescaped = _ . unescape ( data ) ,
254
+ mapCharacters = {
255
+ ''' : '\''
256
+ } ;
257
+
258
+ _ . each ( mapCharacters , function ( value , key ) {
259
+ unescaped = unescaped . replace ( key , value ) ;
260
+ } ) ;
261
+
262
+ return unescaped ;
263
+ } ,
264
+
245
265
/**
246
266
* Converts PHP IntlFormatter format to moment format.
247
267
*
Original file line number Diff line number Diff line change 1327
1327
'>' : '>' ,
1328
1328
'"' : '"' ,
1329
1329
"'" : ''' ,
1330
- '`' : '`'
1330
+ '`' : '`' ,
1331
+ "'" : ''' ,
1331
1332
} ;
1332
1333
var unescapeMap = _ . invert ( escapeMap ) ;
1333
1334
You can’t perform that action at this time.
0 commit comments