Skip to content

Commit 59b89dc

Browse files
author
Rick Owens
committed
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.
1 parent 4f13734 commit 59b89dc

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

Data/Attoparsec/ByteString/Internal.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,14 @@ peekWord8' = T.Parser $ \t pos more lose succ ->
426426
in ensureSuspended 1 t pos more lose succ'
427427
{-# INLINE peekWord8' #-}
428428

429-
-- | Match either a single newline character @\'\\n\'@, or a carriage
430-
-- return followed by a newline character @\"\\r\\n\"@.
429+
-- | Match a carriage return followed by a newline character @\"\\r\\n\"@,
430+
-- a single newline character @\'\\n\'@, or a single carriage return
431+
-- @\'\\r\'@.
431432
endOfLine :: Parser ()
432-
endOfLine = (word8 10 >> return ()) <|> (string "\r\n" >> return ())
433+
endOfLine =
434+
(string "\r\n" >> return ())
435+
<|> (word8 10 >> return ())
436+
<|> (word8 13 >> return ())
433437

434438
-- | Terminal failure continuation.
435439
failK :: Failure a

Data/Attoparsec/Text/Internal.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,14 @@ peekChar' = do
428428
return $! T.unsafeHead s
429429
{-# INLINE peekChar' #-}
430430

431-
-- | Match either a single newline character @\'\\n\'@, or a carriage
432-
-- return followed by a newline character @\"\\r\\n\"@.
431+
-- | Match a carriage return followed by a newline character @\"\\r\\n\"@,
432+
-- a single newline character @\'\\n\'@, or a single carriage return
433+
-- @\'\\r\'@.
433434
endOfLine :: Parser ()
434-
endOfLine = (char '\n' >> return ()) <|> (string "\r\n" >> return ())
435+
endOfLine =
436+
(string "\r\n" >> return ())
437+
<|> (char '\n' >> return ())
438+
<|> (char '\r' >> return ())
435439

436440
-- | Terminal failure continuation.
437441
failK :: Failure a

0 commit comments

Comments
 (0)