Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/cs 38886 #1033

Merged
merged 3 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)) {
abhinav-from-contentstack marked this conversation as resolved.
Show resolved Hide resolved
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.