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

toArrays() of single field file appears to omit the final row #146

Open
harrishudson opened this issue Nov 9, 2020 · 3 comments
Open

toArrays() of single field file appears to omit the final row #146

harrishudson opened this issue Nov 9, 2020 · 3 comments

Comments

@harrishudson
Copy link

Is this a bug? If not consider asking on StackOverflow.

Not sure if this is a bug or there is a workaround but this doesn't appear to be expected behaviour.

Subject of the issue

toArrays() of single field file appears to omit the final row

Environment

  • Platform: Node | Browser
  • Version: Chrome 50
  • Usage: Load from file | Load from Ajax | Hooks

Steps to reproduce

var result = $.csv.toArrays(input);

Input;

"All work"
"and no play"
"makes Jack"
"a dull boy..."

Expected behaviour

[
  [
    "All work"
  ],
  [
    "and no play"
  ],
  [
    "makes Jack"
  ],
  [
    "a dull boy..."
  ]
]

Actual behaviour

[
  [
    "All work"
  ],
  [
    "and no play"
  ],
  [
    "makes Jack"
  ]
]

References

@evanplaice
Copy link
Owner

Simple solution. Add a newline at the end of the CSV file. This is actually spec behavior.

I can also work out a solution to flush the last line if it isn't blank. I'm pretty sure I already solved this issue in @vanillaes/csv.

@harrishudson
Copy link
Author

Thanks for responding. Oh okay, if that is per specs then happy to close this issue. Compliance to specs is a big feature of this parser and is the main reason I chose this to utilitze it as the core parser in my project (Visual Field) - compared to other js parsing alternatives. I'm a little reluctant to implement your simple solution however, as Visual Field allows end users to provide either a delimited file as input or remote CORS delimited datasets as input (its not my own delimited or CSV input file). So, I am typically at the mercy of published datasets - and I don't really want to alter or mangle users raw input data in any way. I am curious however as to why there appears to be different parsing behaviour dependent upon the final input line being a single field or multiple fields without a trailing new line. For example, parsing a file of just "a" (without a new line) produces an empty array [] whereas, parsing "a","b" (without a new line) produces [["a","b"]]. Seems strange to me but if that behaviour is per specs, then that's fine. Thank you.

@evanplaice
Copy link
Owner

TBH, the spec kind of sucks. It's not like CSV started with a well-defined spec. The RFC is more a list of common characteristics that make up a CSV file.

Adding support for inputs that have no trailing newline isn't a big deal. I just need some time to patch and test. This codebase is very ugly because it was written prior to modern (ie ES6+) JS.

As for your last question. I don't know, I'll have to see what it outputs once the first fix is in. Could be a very obscure bug that hasn't been discovered yet.

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