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

C++ Datetime Parsing #1220

Merged
merged 3 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
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
Fix CSV parsing for strings with double quotes
  • Loading branch information
texodus committed Oct 12, 2020
commit 2c9ede91b1c602959ba525909e676511f3ebda27
4 changes: 3 additions & 1 deletion packages/perspective/src/js/view_formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ const csvFormatter = Object.assign({}, jsonFormatter, {
switch (typeof x) {
case "object":
case "string":
return x.indexOf(delimiter) > -1 ? `"${x}"` : x.toString();
// CSV escapes with double double quotes, for real.
// [Section 2.7 of the fake CSV spec](https://tools.ietf.org/html/rfc4180)
return x.indexOf(delimiter) > -1 ? `"${x.replace(/\"/g, '""')}"` : x.toString();
case "number":
return x;
case "boolean":
Expand Down
14 changes: 14 additions & 0 deletions packages/perspective/test/js/constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,20 @@ module.exports = perspective => {
table.delete();
});

it("Handles strings with quotation characters and commas", async function() {
let table = perspective.table({x: "string", y: "integer"});
table.update([
{x: "Test, hello!", y: 1},
{x: 'Test2"', y: 2},
{x: 'Test3, Hello!"', y: 3}
]);
let view = table.view();
let result = await view.to_csv();
expect(result).toEqual(`x,y\r\n"Test, hello!",1\r\nTest2",2\r\n"Test3, Hello!""",3`);
view.delete();
table.delete();
});

it("Transitively loads a CSV created from `to_csv()` on a table with a datetime column", async function() {
// Assert that the CSV parser can handle POSIX timestamps.
let table = perspective.table(arrow_date_data);
Expand Down