mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 10:55:37 +00:00
trim content builder model attributes
This commit is contained in:
parent
9b20f27657
commit
b9c67e7f8f
@ -10,6 +10,7 @@ const {
|
||||
createManager,
|
||||
removeColsLine,
|
||||
reorderList,
|
||||
deepTrimObject,
|
||||
} = require('../utils/helpers.js');
|
||||
|
||||
module.exports = {
|
||||
@ -336,8 +337,9 @@ module.exports = {
|
||||
});
|
||||
|
||||
Object.assign(attributesNotConfigurable, attrs);
|
||||
const trimmedNotConfigurableAttributes = deepTrimObject(attributesNotConfigurable);
|
||||
|
||||
return [attributesNotConfigurable, errors];
|
||||
return [trimmedNotConfigurableAttributes, errors];
|
||||
},
|
||||
|
||||
clearRelations: (model, source, force) => {
|
||||
|
||||
@ -44,7 +44,7 @@ const removeColsLine = (manager, list) => {
|
||||
const reorderList = (manager, list) => {
|
||||
const array = createArrayOfLastEls(manager, list);
|
||||
const lines = [];
|
||||
|
||||
|
||||
array.forEach((item, i) => {
|
||||
const { elements } = getElementsOnALine(manager, i, list);
|
||||
lines.push(elements);
|
||||
@ -57,7 +57,7 @@ const reorderList = (manager, list) => {
|
||||
return acc.concat(line);
|
||||
}, [])
|
||||
.filter(a => a !== undefined);
|
||||
|
||||
|
||||
return List(flattenDeep(reordered));
|
||||
};
|
||||
|
||||
@ -65,11 +65,31 @@ const escapeNewlines = (content, placeholder = '\n') => {
|
||||
return content.replace(/[\r\n]+/g, placeholder);
|
||||
}
|
||||
|
||||
const deepTrimObject = attribute => {
|
||||
if (Array.isArray(attribute)) {
|
||||
return attribute.map(deepTrimObject);
|
||||
}
|
||||
|
||||
if (typeof attribute === 'object') {
|
||||
return Object.entries(attribute)
|
||||
.reduce((acc, [key, value]) => {
|
||||
const trimmedObject = deepTrimObject(value);
|
||||
|
||||
return { ...acc, [key]: trimmedObject };
|
||||
}, {});
|
||||
}
|
||||
|
||||
return typeof attribute === 'string'
|
||||
? attribute.trim()
|
||||
: attribute;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
createArrayOfLastEls,
|
||||
createManager,
|
||||
getElementsOnALine,
|
||||
removeColsLine,
|
||||
reorderList,
|
||||
escapeNewlines
|
||||
};
|
||||
escapeNewlines,
|
||||
deepTrimObject
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user