mirror of
https://github.com/byteverse/colonnade.git
synced 2026-08-31 00:13:52 +02:00
properly escape carriage returns
This commit is contained in:
parent
3bfd8265bc
commit
e17df21a2b
@ -40,8 +40,8 @@ import Control.Applicative
|
|||||||
import Data.Monoid
|
import Data.Monoid
|
||||||
|
|
||||||
byteStringChar8 :: Siphon ByteString
|
byteStringChar8 :: Siphon ByteString
|
||||||
byteStringChar8 = Siphon
|
byteStringChar8 = Siphon
|
||||||
escape
|
escape
|
||||||
encodeRow
|
encodeRow
|
||||||
(A.parse (row comma))
|
(A.parse (row comma))
|
||||||
B.null
|
B.null
|
||||||
@ -54,7 +54,7 @@ encodeRow = id
|
|||||||
. coerce
|
. coerce
|
||||||
|
|
||||||
escape :: ByteString -> Escaped ByteString
|
escape :: ByteString -> Escaped ByteString
|
||||||
escape t = case B.find (\c -> c == newline || c == comma || c == doubleQuote) t of
|
escape t = case B.find (\c -> c == newline || c == cr || c == comma || c == doubleQuote) t of
|
||||||
Nothing -> Escaped t
|
Nothing -> Escaped t
|
||||||
Just _ -> escapeAlways t
|
Just _ -> escapeAlways t
|
||||||
|
|
||||||
|
|||||||
@ -30,9 +30,9 @@ main = defaultMain tests
|
|||||||
|
|
||||||
tests :: [Test]
|
tests :: [Test]
|
||||||
tests =
|
tests =
|
||||||
[ testGroup "ByteString encode/decode"
|
[ testGroup "ByteString encode/decode"
|
||||||
[ testCase "Headless Encoding (int,char,bool)" testEncodingA
|
[ testCase "Headless Encoding (int,char,bool)" testEncodingA
|
||||||
, testProperty "Headless Isomorphism (int,char,bool)"
|
, testProperty "Headless Isomorphism (int,char,bool)"
|
||||||
$ propIsoPipe $
|
$ propIsoPipe $
|
||||||
(SE.pipe SC.byteStringChar8 encodingA)
|
(SE.pipe SC.byteStringChar8 encodingA)
|
||||||
>->
|
>->
|
||||||
@ -64,7 +64,7 @@ byteStringEncodeChar = BC8.singleton
|
|||||||
|
|
||||||
byteStringEncodeInt :: Int -> ByteString
|
byteStringEncodeInt :: Int -> ByteString
|
||||||
byteStringEncodeInt = LByteString.toStrict
|
byteStringEncodeInt = LByteString.toStrict
|
||||||
. Builder.toLazyByteString
|
. Builder.toLazyByteString
|
||||||
. Builder.intDec
|
. Builder.intDec
|
||||||
|
|
||||||
byteStringEncodeBool :: Bool -> ByteString
|
byteStringEncodeBool :: Bool -> ByteString
|
||||||
@ -84,7 +84,7 @@ encodingA = contramap tripleToPairs
|
|||||||
$ divided (Encoding.headless byteStringEncodeInt)
|
$ divided (Encoding.headless byteStringEncodeInt)
|
||||||
$ divided (Encoding.headless byteStringEncodeChar)
|
$ divided (Encoding.headless byteStringEncodeChar)
|
||||||
$ divided (Encoding.headless byteStringEncodeBool)
|
$ divided (Encoding.headless byteStringEncodeBool)
|
||||||
$ conquered
|
$ conquered
|
||||||
|
|
||||||
tripleToPairs :: (a,b,c) -> (a,(b,(c,())))
|
tripleToPairs :: (a,b,c) -> (a,(b,(c,())))
|
||||||
tripleToPairs (a,b,c) = (a,(b,(c,())))
|
tripleToPairs (a,b,c) = (a,(b,(c,())))
|
||||||
@ -93,8 +93,8 @@ propIsoPipe :: Eq a => Pipe a a Identity () -> [a] -> Bool
|
|||||||
propIsoPipe p as = (Pipes.toList $ each as >-> p) == as
|
propIsoPipe p as = (Pipes.toList $ each as >-> p) == as
|
||||||
|
|
||||||
testEncodingA :: Assertion
|
testEncodingA :: Assertion
|
||||||
testEncodingA =
|
testEncodingA =
|
||||||
( ByteString.concat $ Pipes.toList $
|
( ByteString.concat $ Pipes.toList $
|
||||||
Pipes.yield (4,'c',False) >-> SE.pipe SC.byteStringChar8 encodingA
|
Pipes.yield (4,'c',False) >-> SE.pipe SC.byteStringChar8 encodingA
|
||||||
) @?= "4,c,false\n"
|
) @?= "4,c,false\n"
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user