Skip to content

Add Quirk for single invalid UTF8 file. #6588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Cabal/Distribution/PackageDescription/Quirks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,11 @@ patches = Map.fromList
(Fingerprint 12475837388692175691 18053834261188158945)
(Fingerprint 16279938253437334942 15753349540193002309)
(bsReplace "9223372036854775807" "999")

-- Not UTF8
, mk "Name: nat\nVersion: 0.1\nDescription: Implementation of natural numbers and integers by a binary\n representation. The implementation is supposed to be lazy and\n "
(Fingerprint 9222512268705577108 13085311382746579495)
(Fingerprint 17468921266614378430 13221316288008291892)
(bsReplace "\xf6" "\xc3\xb6")
]
where
mk a b c d = ((a, b), (c, d))
Expand Down
10 changes: 7 additions & 3 deletions Cabal/tests/HackageTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import Data.Monoid (Sum (..))
import Distribution.PackageDescription.Check (PackageCheck (..), checkPackage)
import Distribution.PackageDescription.PrettyPrint (showGenericPackageDescription)
import Distribution.PackageDescription.Quirks (patchQuirks)
import Distribution.Simple.Utils (fromUTF8BS, toUTF8BS)
import Distribution.Simple.Utils (fromUTF8BS, toUTF8BS, fromUTF8BS)
import System.Directory (getAppUserDataDirectory)
import System.Environment (lookupEnv)
import System.Exit (exitFailure)
Expand Down Expand Up @@ -238,9 +238,9 @@ roundtripTest testFieldsTransform fpath bs = do

-- fromParsecField, "shallow" parser/pretty roundtrip
when testFieldsTransform $
if checkUTF8 bs
if checkUTF8 patchedBs
then do
parsecFields <- assertRight $ Parsec.readFields $ snd $ patchQuirks bs
parsecFields <- assertRight $ Parsec.readFields patchedBs
let prettyFields = PP.fromParsecFields parsecFields
let bs'' = PP.showFields (return []) prettyFields
z0 <- parse "3rd" (toUTF8BS bs'')
Expand All @@ -252,6 +252,8 @@ roundtripTest testFieldsTransform fpath bs = do

return (Sum 1)
where
patchedBs = snd (patchQuirks bs)

checkUTF8 bs' = replacementChar `notElem` fromUTF8BS bs' where
replacementChar = '\xfffd'

Expand All @@ -265,6 +267,7 @@ roundtripTest testFieldsTransform fpath bs = do
assertEqual' bs' x y = unless (x == y || fpath == "ixset/1.0.4/ixset.cabal") $ do
putStrLn fpath
#ifdef MIN_VERSION_tree_diff
putStrLn "====== tree-diff:"
print $ ansiWlEditExprCompact $ ediff x y
#else
putStrLn "<<<<<<"
Expand All @@ -273,6 +276,7 @@ roundtripTest testFieldsTransform fpath bs = do
print y
putStrLn ">>>>>>"
#endif
putStrLn "====== contents:"
putStrLn bs'
exitFailure

Expand Down