8 ms·
RFC 4180: Common Format and MIME Type for CSV Files (2005)
- aliasEli 5y agoAnyone who has written software to import CSV files knows that in general it's a complete mess. Also, geneticists have been forced to rename certain gene names because Excel messed them up[0]. It would be nice if this standard would be generally accepted. This standard is from 2005 and it is pretty clear that it is not universally used. [0] https://www.theregister.com/2020/08/06/excel_gene_names/ https://www.theregister.com/2020/08/06/excel_gene_names/
- olau 5y agoExcel is the ultimate bane of CSV files. If Microsoft would fix Excel and distribute the fixes to old Excels, then life would be good again.
- chrismorgan 5y agoBut they will never do that because that would break existing systems that depend on the old behaviour.
- wolrah 5y ago> But they will never do that because that would break existing systems that depend on the old behaviour. Which is an inevitability for anything that's been a dependency for long enough. Either you admit that things have to change and sometimes shit that's been secretly broken for years will have to change too, or you give in to the shit and admit that you can never solve any problems that made it to production. Both answers suck, but one is a lot more suck so I choose the "fix it anyways and if something else turns out to have depended on the brokeness then add that to the list of shit to fix" approach whenever possible.
- aliasEli 5y agoIt is not just Excel, there are a lot of systems that export CSV. Many of them are broken. Examples: - double quotes in text fields - using the wrong decimal separator, should it be "," or "." - using the wrong column separator, should be "," or ";"
- WorldMaker 5y agoThe "General" data column behavior thing that caused the incorrect parsing of gene names as Dates goes all the way back to the original Visicalc. Are you suggesting Microsoft should patch Visicalc and Lotus 1-2-3 as well?
- FranOntanaya 5y agoBy that logic though, all text formats are a mess because text processors will autocorrect and break the formatting.
- dspillett 5y agoWe've had similar issues with clients using 1-2-1 as a meeting type name. When data about those records are exported to CSV and loaded by Excel, it gets seen as the date 2001-02-01 (or, presumably, 2001-01-02 for those using a US locale in their setup) even if the value is quoted (which we hoped would be interpreted as "this value is definitely nothing fancier than a basic string", but it was not). > This standard is from 2005 and it is pretty clear that it is not universally used. Unfortunately a lot of non-conforming software can't change or they risk compatibility problems with old versions of themselves. 2005 is relatively recent in the history of CSV files.
- viraptor 5y agoOpening CSV in excel rather than importing is pretty much broken by design. Import data from text and you can set the column types. Open by default and suffer consequences.
- dspillett 5y agoYou are not at all wrong, but unfortunately "you are opening it wrong" did not fly with the client for us in this case.
- gardaani 5y agoThe reason I don't like CSV is that CSV files can use any text encoding: ASCII, ISO-8859, UTF-8.. It's not nice to try to guess the encoding when reading files. RFC 4180 also fails to define the default text encoding. It seems that text encoding can be given only when MIME type is given for the file. JSON is so much easier.
- formerly_proven 5y agoExcel generates RFC-compliant CSV files if you are using the en-us/en-uk locales, but not for many other locales. Of course, this is a system-wide setting, and Excel has no option to generate a standard CSV independent of locale.
- shellac 5y agoI used Excel recently and it added a BOM, which is pretty awful. Is there any way to stop that nonsense?
- cpach 5y agoAFAIK: Nope. Microsoft loves that BOM, for reasons I cannot comprehend.
- andylynch 5y agoAlmost certainly for backwards compatibility. Excel in particular uses the BOM as a single to open a file in a Unicode encoding, rather than cp1252 etc.
- dbsmith83 5y agoI use a script to strip it from the file. Definitely not ideal.
- dspillett 5y ago> the en-us/en-uk locales Though be careful if you communicate with people using both locals. Things interpreted as dates will get corrupted in fun ways.
- throw0101a 5y agoSadly "ASCII delimited" text, using ASCI 28 to 31, doesn't seem to be a thing: * https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text * http://en.wikipedia.org/wiki/Unit_separator http://en.wikipedia.org/wiki/Unit_separator
- Nullabillity 5y agoI don't really see the point... Using special characters makes it harder to manipulate by hand, and you still don't solve conflicts (where content is able to corrupt the container structure). Ultimately, the only safe way is to use Pascal string-style length prefixes. Escaping is too easy to ignore, until it comes back to bite you in the ass. Balanced delimiters break as soon as the content contains invalid data (or is delimited according to a different convention than the container).
- jrochkind1 5y agoIt's much less likely that content is going to include ASCII 28 to 31 than that it will include a comma or a tab. But you're right, certainly not impossible. I think the human-editability you mention may be a major reason why comma-separated has been such a practical winner? Since ASCII 28 to 31 are invisible or indistinguishable in most editors, I suspect a format relying on them would be subject to routine corruption. (I have some experience working with a "legacy" "binary" format which DOES use those ASCII separator values... https://en.wikipedia.org/wiki/MARC_standards https://en.wikipedia.org/wiki/MARC_standards)
- Nullabillity 5y ago> It's much less likely that content is going to include ASCII 28 to 31 than that it will include a comma or a tab. But you're right, certainly not impossible. Yeah, that's the same problem as UTF-8's almost-compatibility with ASCII. Things work, until they break spectacularly. Ultimately, you either have to solve the issue properly, or keep it visible enough that people are forced to handle it.
- 5y ago
- yakovsh2 5y ago(I'm the author of the RFC) Not sure why this is trending now, but this RFC is being revised now: https://datatracker.ietf.org/doc/html/draft-shafranovich-rfc4180-bis https://datatracker.ietf.org/doc/html/draft-shafranovich-rfc... Suggestions and comments are welcome here: https://github.com/nightwatchcybersecurity/rfc4180-bis https://github.com/nightwatchcybersecurity/rfc4180-bis
- jtvjan 5y agoI think we should just stop using commas and newlines and start using the ASCII unit separator and record separator. It would alleviate most quoting and escaping issues because those two rarely appear in actual text.
- teddyh 5y agoSure, maybe, but that won’t be CSV.
- Jiocus 5y agoMaybe that would be an "SSV"? Separator Separated Values file.
- SahAssar 5y agoThat would just make it easier to implement the standard in a way that works most of the time but breaks on valid input. Why would that be desirable?
- colejohnson66 5y agoUntil I can type those ASCII separators on my keyboard, they’re not going to happen. That’s why CSV won out: the comma key already existed.
- skissane 5y agoFor terminal mode applications, unit separator is Control+Underscore and record separator is Control+Caret (Ctrl+Shift+6 on a US English keyboard). However, many terminal mode applications intercept those keys and expect them to be commands rather than data. Often there is some kind of quote key which you can press first. In readline and vim, the quote key is Ctrl+V. In emacs, it is Ctrl+Q instead. GUI applications are more variable. But vim and emacs still support their respective quote keys in GUI mode. And if you have to type this a lot, you can modify your vim/emacs/readline/etc configuration to remove the requirement for the quote key to be pressed first.
- temp8964 5y agoI recommend CSVY (CSV with YAML frontmatter, https://csvy.org/ https://csvy.org/), which solves several problems in CSV. Currently R data.table supports read and write csvy format. https://www.rdocumentation.org/packages/data.table/versions/1.14.0/topics/fread https://www.rdocumentation.org/packages/data.table/versions/...
- slver 5y agoCSV in the abstract has no problems. The problem is two tools attempting to interact by using subtly incompatible versions of CSV. And CSVY just adds one more of those.
- sonjaqql 5y agoThis is timely for me - I was just sharing this 2014 article with my team. http://thomasburette.com/blog/2014/05/25/so-you-want-to-write-your-own-CSV-code/ http://thomasburette.com/blog/2014/05/25/so-you-want-to-writ... It made an impact on my approach to CSV handling, and helped me understand, "just because I can, doesn't mean I should".
- edoceo 5y agoOh heck. I'm cited reference #5 (almost last) but the link to my site is broken. I'll have to put a 301 on there.
- mattowen_uk 5y agoOk, so now I know that text/csv is proper mime type, I have to ask, why don't browsers offer a native way to view CSVs as a [html] table complete with sorting and filtering?