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

Fails if attribute is named 'set' #185

Closed
3 of 5 tasks
jgutix opened this issue May 16, 2021 · 2 comments · Fixed by #186
Closed
3 of 5 tasks

Fails if attribute is named 'set' #185

jgutix opened this issue May 16, 2021 · 2 comments · Fixed by #186
Labels
bug json2csv JSON to CSV

Comments

@jgutix
Copy link

jgutix commented May 16, 2021

Background Information

  • Module Version: 3.11.1
  • Node/Browser Version: 14

The issue I'm reporting is with:

  • json2csv
  • csv2json

I have...

  • searched to see if an issue has already been reported.
  • verified that my JSON/CSV data is valid (using something like http://jsonlint.com or https://csvlint.io/).
  • tried upgrading to the latest version of json-2-csv (since the issue may already be fixed).

Expected Behavior

Should allow field name/attribute to be name "set"

Actual Behavior

Will throw error:
TypeError: fieldValue.includes is not a function

Data Sample

CSV:


(or)

JSON:

[{
	"set": "test",
	"otherfieldname": "test2"
}]

Code Example

import converter from 'json-2-csv';

const csv = await converter.json2csvAsync([{set: 'test', otherfieldname: 'test2'}]);
console.log(csv)
mrodrig added a commit that referenced this issue May 19, 2021
As reported in #185, there was a bug where header values could not have
the same name as a Map method. This is because the code was naively
checking for the existence of a possible title field by simply accessing
the raw value of the Map. This resulted in Map.prototype.set being
returned when the "set" JSON key name was used. The logic has been
updated to check for header titles against an Object.keys list now since
that will not include prototype methods for the underlying Map object.

Fixes #185
mrodrig added a commit that referenced this issue May 19, 2021
@mrodrig
Copy link
Owner

mrodrig commented May 19, 2021

Thanks for reporting this @jgutix! I found the issue and have a pull request open for the fix. I'm going to see if I can push a release out later today with this and hopefully a fix for another issue that was reported. I'll comment with the version number once it goes out.

mrodrig added a commit that referenced this issue May 20, 2021
* Validate field titles against Object.keys list

As reported in #185, there was a bug where header values could not have
the same name as a Map method. This is because the code was naively
checking for the existence of a possible title field by simply accessing
the raw value of the Map. This resulted in Map.prototype.set being
returned when the "set" JSON key name was used. The logic has been
updated to check for header titles against an Object.keys list now since
that will not include prototype methods for the underlying Map object.

Fixes #185

* Add test for #185.

* Add Node 16,  remove Node 10 for travis test cfg.
@mrodrig
Copy link
Owner

mrodrig commented May 20, 2021

Thanks again @jgutix. I just released the fix in version 3.12.0 which should be available on NPM now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug json2csv JSON to CSV
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants