fix another quickcheck property broken by NUL in Arbitrary String

This commit is contained in:
Joey Hess 2019-12-06 13:12:35 -04:00
parent 3ece4758c6
commit 4aaef14c61
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -35,13 +35,21 @@ decode b = case S.uncons b of
encode :: RawFilePath -> S.ByteString
encode s = encodeBS $ "\"" ++ encode_c (decodeBS s) ++ "\""
{- For quickcheck.
-
- See comment on Utility.Format.prop_encode_c_decode_c
-_roundtrip for
- why this only tests chars < 256
-}
prop_encode_decode_roundtrip :: FilePath -> Bool
prop_encode_decode_roundtrip s = s' == fromRawFilePath (decode (encode (toRawFilePath s')))
prop_encode_decode_roundtrip s = s' ==
fromRawFilePath (decode (encode (toRawFilePath s')))
where
s' = filter (\c -> ord c < 256) s
s' = nonul (nohigh s)
-- Encoding and then decoding roundtrips only when
-- the string does not contain high unicode, because eg,
-- both "\12345" and "\227\128\185" are encoded to
-- "\343\200\271".
--
-- This property papers over the problem, by only
-- testing chars < 256.
nohigh = filter (\c -> ord c < 256)
-- A String can contain a NUL, but toRawFilePath
-- truncates on the NUL, which is generally fine
-- because unix filenames cannot contain NUL.
-- So the encoding only roundtrips when there is no nul.
nonul = filter (/= '\NUL')