Skip to content

Commit 47290c8

Browse files
committed
Adding the same treatment for description (formatted) field that we use for CmsPage to Category, Collection, and Product descriptions. They now behave the same way as CmsPage when editing markup. They now handle all the CKEditor types, too.
1 parent 6f3ef46 commit 47290c8

3 files changed

Lines changed: 25 additions & 3 deletions

File tree

packages/evershop/src/modules/catalog/graphql/types/Category/Category.resolvers.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,14 @@ export default {
179179
},
180180
description: ({ description }) => {
181181
try {
182-
return JSON.parse(description);
182+
const replacements = {
183+
'&lt;': '<',
184+
'&gt;': '>'
185+
};
186+
const jsonText = description
187+
? description.replace(/&lt;|&gt;/g, (match) => replacements[match])
188+
: '[]';
189+
return JSON.parse(jsonText);
183190
} catch (e) {
184191
// This is for backward compatibility. If the description is not a JSON string then it is a raw HTML block
185192
const rowId = `r__${uuidv4()}`;

packages/evershop/src/modules/catalog/graphql/types/Collection/Collection.resolvers.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@ export default {
3030
},
3131
description: ({ description }) => {
3232
try {
33-
return JSON.parse(description);
33+
const replacements = {
34+
'&lt;': '<',
35+
'&gt;': '>'
36+
};
37+
const jsonText = description
38+
? description.replace(/&lt;|&gt;/g, (match) => replacements[match])
39+
: '[]';
40+
return JSON.parse(jsonText);
3441
} catch (e) {
3542
// This is for backward compatibility. If the description is not a JSON string then it is a raw HTML block
3643
const rowId = `r__${uuidv4()}`;

packages/evershop/src/modules/catalog/graphql/types/Product/Product.resolvers.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ export default {
2626
return [];
2727
}
2828
try {
29-
return JSON.parse(description);
29+
//return JSON.parse(description);
30+
const replacements = {
31+
'&lt;': '<',
32+
'&gt;': '>'
33+
};
34+
const jsonText = description
35+
? description.replace(/&lt;|&gt;/g, (match) => replacements[match])
36+
: '[]';
37+
return JSON.parse(jsonText);
3038
} catch (e) {
3139
// This is for backward compatibility. If the description is not a JSON string then it is a raw HTML block
3240
const rowId = `r__${uuidv4()}`;

0 commit comments

Comments
 (0)