From a18b7822a54c3ec00e1297d7b1c937153d67b1b1 Mon Sep 17 00:00:00 2001 From: Francois Maillet Date: Fri, 22 Aug 2014 18:09:20 -0400 Subject: [PATCH] Fixed infinite loop when parsing csv line that ends with a carriage return --- utils/parse_context.h | 5 ++++- utils/testing/csv_parsing_test.cc | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/utils/parse_context.h b/utils/parse_context.h index e7224dc..febbfe3 100644 --- a/utils/parse_context.h +++ b/utils/parse_context.h @@ -485,7 +485,10 @@ struct Parse_Context { if (*cur_ != '\r') return false; // deal with DOS line endings - return match_literal("\r\n"); + if(match_literal("\r\n") || *cur_ == '\r') + return true; + + return false; } void expect_eol(const char * error = "expected eol") diff --git a/utils/testing/csv_parsing_test.cc b/utils/testing/csv_parsing_test.cc index 5e83efc..e2e86d0 100644 --- a/utils/testing/csv_parsing_test.cc +++ b/utils/testing/csv_parsing_test.cc @@ -41,4 +41,9 @@ BOOST_AUTO_TEST_CASE (test1) testCsvLine("\"\"", {""}); testCsvLine("\"\",", {"",""}); testCsvLine("\"\",\"\"", {"",""}); + + // check that we handle all line endings correctly + testCsvLine("\n", {}); + testCsvLine("\r\n", {}); + testCsvLine("\r", {}); }