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

[front] fix(csv) - csv parsing #9121

Merged
merged 8 commits into from
Dec 4, 2024
Merged

[front] fix(csv) - csv parsing #9121

merged 8 commits into from
Dec 4, 2024

Conversation

aubin-tchoi
Copy link
Contributor

@aubin-tchoi aubin-tchoi commented Dec 4, 2024

Description

> {}["constructor"] [Function: Object]

Tested with:

constructor toString 0 undefined null [] {}
0 1 undefined 2   null  

Risk

Low.

Deploy Plan

  • Deploy front.

@aubin-tchoi aubin-tchoi requested a review from Fraggle December 4, 2024 13:56
@aubin-tchoi aubin-tchoi self-assigned this Dec 4, 2024
for await (const anyRecord of parser) {
if (i++ >= rowIndex) {
const record = anyRecord as string[];
for (const [i, h] of header.entries()) {
try {
valuesByCol[h] ??= [];
(valuesByCol[h] as string[]).push(record[i] || "");
(valuesByCol[h] as string[]).push(record[i] ?? "");
Copy link
Contributor

Choose a reason for hiding this comment

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

What types of value are we going to get that we didn't get? Are they desirable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this change is preemptive and not related to the fix, here if we get a value of 0 in record[i] it gets converted to ""

@@ -369,14 +369,14 @@ export async function rowsFromCsv({

let i = 0;
const parser = parse(csv, { delimiter });
const valuesByCol: Record<string, string[]> = {};
const valuesByCol: Record<string, string[]> = Object.create(null);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain a bit more? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mb completely forgot

Copy link
Contributor Author

Choose a reason for hiding this comment

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

here it was {}["constructor"] that caused the issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@aubin-tchoi aubin-tchoi Dec 4, 2024

Choose a reason for hiding this comment

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

@spolu added a comment in code to explain the Object.create(null)

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@aubin-tchoi aubin-tchoi merged commit d8c3779 into main Dec 4, 2024
4 checks passed
@aubin-tchoi aubin-tchoi deleted the fix-csv-parsing branch December 4, 2024 14:48
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

Successfully merging this pull request may close these issues.

2 participants