Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
fixup: escape double quotes properly
  • Loading branch information
BridgeAR committed Feb 6, 2018
commit de425e244b205db482085c5f8994d81bba298813
2 changes: 2 additions & 0 deletions benchmark/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ if (showProgress) {
conf += ` ${key}=${inspect(data.conf[key])}`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually wondering, is there a place where we benefit from using inspect here as opposed to simply String(data.conf[key])? Because as far as I can tell, conf is generally number, string or true/false.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do because we will actually be able to distinguish the data types by using util.inspect. By only converting it to a string, the string 'true' would look the same as the boolean true.

Copy link
Copy Markdown
Contributor

@apapirovski apapirovski Feb 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair.

Personally, I'm not sure I actually love that part of the functionality but obviously that's not something that needs to be addressed in this PR. Since it's generating CSV, having true and "true" be equivalent is almost preferable to me.

One other thing... util.inspect will do the following:

util.inspect("true");
// '\'true\''
JSON.stringify("true");
// '"true"'

The former doesn't seem correct for the purposes of CSV.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW one of the problems with single quotes is there seems to be no accepted way of handling them. Some parsers seem to treat them as equivalent to double quotes (meaning they need to be escaped) and others treat them as just a character.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@apapirovski I wrote this with the RFC 4180 specs in mind. If a parser does something else (and many do), then that is just tough luck. Creating CSV files that work in all parsers is a very big challenge. We just need to make sure it works with read.csv in R.

}
conf = conf.slice(1);
// Escape quotes (") for correct csv formatting
conf = conf.replace(/"/g, '""');

console.log(`"${job.binary}", "${job.filename}", "${conf}", ` +
`${data.rate}, ${data.time}`);
Expand Down