From 59b89dcd7b6327b2c6c7f716918d7ca86de18eb2 Mon Sep 17 00:00:00 2001 From: Rick Owens Date: Tue, 5 Jan 2016 11:54:57 -0600 Subject: [PATCH] Added "\r" to the valid line terminators. ... "\r" still exists in many places in the wild, mainly because of Mac OS. For instance we recently hit a case where Gmail would export "\r" delimited CSV when exporting contacts. --- Data/Attoparsec/ByteString/Internal.hs | 10 +++++++--- Data/Attoparsec/Text/Internal.hs | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Data/Attoparsec/ByteString/Internal.hs b/Data/Attoparsec/ByteString/Internal.hs index ceb8085d..a1959788 100644 --- a/Data/Attoparsec/ByteString/Internal.hs +++ b/Data/Attoparsec/ByteString/Internal.hs @@ -426,10 +426,14 @@ peekWord8' = T.Parser $ \t pos more lose succ -> in ensureSuspended 1 t pos more lose succ' {-# INLINE peekWord8' #-} --- | Match either a single newline character @\'\\n\'@, or a carriage --- return followed by a newline character @\"\\r\\n\"@. +-- | Match a carriage return followed by a newline character @\"\\r\\n\"@, +-- a single newline character @\'\\n\'@, or a single carriage return +-- @\'\\r\'@. endOfLine :: Parser () -endOfLine = (word8 10 >> return ()) <|> (string "\r\n" >> return ()) +endOfLine = + (string "\r\n" >> return ()) + <|> (word8 10 >> return ()) + <|> (word8 13 >> return ()) -- | Terminal failure continuation. failK :: Failure a diff --git a/Data/Attoparsec/Text/Internal.hs b/Data/Attoparsec/Text/Internal.hs index 172b6002..8782c72a 100644 --- a/Data/Attoparsec/Text/Internal.hs +++ b/Data/Attoparsec/Text/Internal.hs @@ -428,10 +428,14 @@ peekChar' = do return $! T.unsafeHead s {-# INLINE peekChar' #-} --- | Match either a single newline character @\'\\n\'@, or a carriage --- return followed by a newline character @\"\\r\\n\"@. +-- | Match a carriage return followed by a newline character @\"\\r\\n\"@, +-- a single newline character @\'\\n\'@, or a single carriage return +-- @\'\\r\'@. endOfLine :: Parser () -endOfLine = (char '\n' >> return ()) <|> (string "\r\n" >> return ()) +endOfLine = + (string "\r\n" >> return ()) + <|> (char '\n' >> return ()) + <|> (char '\r' >> return ()) -- | Terminal failure continuation. failK :: Failure a