Skip to content

Commit

Permalink
Merge pull request #1033 from contentstack/fix/CS-38886
Browse files Browse the repository at this point in the history
Fix/cs 38886
  • Loading branch information
abhinav-from-contentstack authored Sep 12, 2023
2 parents 0ce5326 + f7674e8 commit f62fabb
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/contentstack-export-to-csv/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-export-to-csv",
"description": "Export entities to csv",
"version": "1.4.1",
"version": "1.4.2",
"author": "Abhinav Gupta @abhinav-from-contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down
18 changes: 17 additions & 1 deletion packages/contentstack-export-to-csv/src/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,22 @@ function exitProgram() {
process.exit();
}

function sanitizeEntries(flatEntry) {
// sanitize against CSV Injections
const CSVRegex = /^[\\+\\=@\\-]/
for (key in flatEntry) {
if (typeof flatEntry[key] === 'string' && flatEntry[key].match(CSVRegex)) {
flatEntry[key] = flatEntry[key].replace(/\"/g, "\"\"");
flatEntry[key] = `"'${flatEntry[key]}"`
} else if (typeof flatEntry[key] === 'object') {
// convert any objects or arrays to string
// to store this data correctly in csv
flatEntry[key] = JSON.stringify(flatEntry[key]);
}
}
return flatEntry;
}

function cleanEntries(entries, language, environments, contentTypeUid) {
const filteredEntries = entries.filter((entry) => {
return entry['locale'] === language;
Expand All @@ -393,6 +409,7 @@ function cleanEntries(entries, language, environments, contentTypeUid) {
}
}
entry = flatten(entry);
entry = sanitizeEntries(entry);
entry['publish_details'] = envArr;
entry['_workflow'] = workflow;
entry['ACL'] = JSON.stringify({}); // setting ACL to empty obj
Expand All @@ -409,7 +426,6 @@ function cleanEntries(entries, language, environments, contentTypeUid) {
delete entry.publishRequest;
return entry;
});
console.log(filteredEntries.length);
}

function getDateTime() {
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@contentstack/cli-cm-bulk-publish": "~1.3.11",
"@contentstack/cli-cm-clone": "~1.4.16",
"@contentstack/cli-cm-export": "~1.8.1",
"@contentstack/cli-cm-export-to-csv": "~1.4.1",
"@contentstack/cli-cm-export-to-csv": "~1.4.2",
"@contentstack/cli-cm-import": "~1.8.3",
"@contentstack/cli-cm-migrate-rte": "~1.4.11",
"@contentstack/cli-cm-seed": "~1.4.15",
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f62fabb

Please sign in to comment.