scc icon indicating copy to clipboard operation
scc copied to clipboard

CSV format is broken

Open alexey-milovidov opened this issue 2 years ago • 7 comments

Describe the bug If filename contains , character, it is not properly quoted in CSV.

To Reproduce Clone this repo and run scc: https://github.com/freeCodeCamp/freeCodeCamp The offending file name is curriculum/challenges/italian/08-data-analysis-with-python/numpy/accessing-and-changing-elements,-rows,-columns.md.

Expected behavior Put filename in quotes ("filename") if needed. The quote " characters should be also escaped as "", example: if filename is Hello, "world", it should be output as "Hello, ""world""". Also take care for newlines, tabs and everything else in filenames.

Desktop (please complete the following information):

  • OS: Linux
  • Version 3.0.0.

alexey-milovidov avatar Apr 09 '22 19:04 alexey-milovidov

Another issue: it outputs one extra empty line at the end.

alexey-milovidov avatar Apr 09 '22 19:04 alexey-milovidov

Thats odd... I was using the standard library CSV stuff in Go which I would have thought would solve this.

boyter avatar Apr 10 '22 23:04 boyter

I checked this right now on the Free Code camp repository and my testing one, and the quoting seems to work properly:

Language,Location,Filename,Lines,Code,Comments,Blanks,Complexity,Bytes
Python,"dir,with,quotes/another,comma,.py","another,comma,.py",1,1,0,0,0,17
Python,",name,with,commas.py",",name,with,commas.py",1,1,0,0,0,17

KAAtheWiseGit avatar Apr 26 '23 16:04 KAAtheWiseGit

Neat perhaps that's the trick then.

When I get some time ill have another look at this. Unless someone wants to solve it before then :)

boyter avatar Apr 27 '23 03:04 boyter

Not fixed.

For example, see https://github.com/anthraxx/linux-hardened/tree/master/drivers/staging/mt7621-pci It has a file, named mediatek,mt7621-pci.txt

And the scc output is:

Plain Text,anthraxx/linux-hardened/drivers/staging/mt7621-pci/mediatek,mt7621-pci.txt,mediatek,mt7621-pci.txt,104,87,0,17,0,3327

The invocation is as follows: ~/go/bin/scc --format csv-stream

alexey-milovidov avatar May 04 '23 20:05 alexey-milovidov

I looked into the code and csv-stream, unlike the cvs format, does not allocate any memory, so it does not use the standard CSV library. There was a bug with that, which was fixed by e77be1ae. But it hasn't been released yet.

KAAtheWiseGit avatar May 05 '23 09:05 KAAtheWiseGit

Yep. I am still working on getting the walking to respect all ignore files properly first, once thats done I can come along and clean up a lot of these issues.

boyter avatar May 07 '23 22:05 boyter