Bug in csv or byLine ?

Tobi G. via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jan 10 07:26:55 PST 2016


On Sunday, 10 January 2016 at 09:41:16 UTC, Keywan Ghadami wrote:
> On Friday, 8 January 2016 at 13:53:06 UTC, Guillaume Chatelet 
> wrote:
> I still do not understand half of the syntax(still learning) 
> but my guess is that it is a bug in the csv reader:
> In 
> https://github.com/D-Programming-Language/phobos/blob/67c95e6de21d5d627e3c57128b4d6e332c82f785/std/csv.d line 1020 calls popfront on the input without checking that it input is empty.
> But this only happen in special case if the last line is \r\n 
> if i understand it correctly.
> I might be totally wrong because it does not match your 
> stackstrace and i did not yet understand everything about this.

Yes. It looks like there is no case to handle '\r' - line endings 
correctly.
https://github.com/D-Programming-Language/phobos/blob/67c95e6de21d5d627e3c57128b4d6e332c82f785/std/csv.d?L=1020#L1020
If '\r' is the last character it will fail, (because it tryes to 
read the next character).

enum data =
"name, surname, age
Joe, Joker, 99\r";  // WILL FAIL


import std.csv, std.stdio;

void main(string[] args)
{
     auto reader = csvReader(data);
	
     foreach(entry; reader)
     {
         writeln(entry);
     }
}


togrue



More information about the Digitalmars-d-learn mailing list