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

Export CSV exports also Array prototype #47

Open
vladrusu04 opened this issue Aug 27, 2020 · 1 comment
Open

Export CSV exports also Array prototype #47

vladrusu04 opened this issue Aug 27, 2020 · 1 comment

Comments

@vladrusu04
Copy link

If you add any methods on Array/Object prototype then the for in loop from getBody() method will try to export it.
https://github.com/alhazmy13/angular-csv-ext/blob/master/Angular-csv.ts#L136

As a fix I would suggest using the hasOwnProperty method to avoid iterate over inherited properties, or maybe use Object.keys() and iterate over them to fully avoid for in loop

How to reproduce:

Array.prototype.myFunct = function () { return this; }

const data = [1, 2, 3];
new AngularCsv(data, 'My Report');

// the output will be a CSV file with
// 1, 2, 3, function () { return this; }

For moment, as a hack workaround I override the toString() method for prototype functions:

Array.prototype.myFunct = myFunct;

function myFunct() { return this; }
myFunct.toString = () => '';
@alhazmy13
Copy link
Owner

Hi @vladrusu04

Can you please send a PR for this?

Thanks

ANicholasson added a commit to ANicholasson/simple-csv-js that referenced this issue Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants