From 779701825e9fc011ec0970daeac05c488bb0da19 Mon Sep 17 00:00:00 2001 From: Jessica Black Date: Thu, 14 Dec 2023 11:19:54 -0800 Subject: [PATCH] Strip `!_fossa.virtual_!` from VSI paths (#1345) --- Changelog.md | 4 ++++ fourmolu.yaml | 8 +++++--- src/App/Fossa/VSI/Types.hs | 5 ++++- test/App/Fossa/VSI/TypesSpec.hs | 30 ++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/Changelog.md b/Changelog.md index d979d0714a..18a77be455 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,4 +1,8 @@ # FOSSA CLI Changelog + +## v3.8.28 +- VSI: no longer reports paths inside of extracted archives with the `!_fossa.virtual_!` literal [#1345](https://github.com/fossas/fossa-cli/pull/1345) + ## v3.8.27 - Maven: Fix a bug that broke maven analysis if the build directory was in a non-standard location ([#1343](https://github.com/fossas/fossa-cli/pull/1343)) diff --git a/fourmolu.yaml b/fourmolu.yaml index 662d9c4306..1114f89a19 100644 --- a/fourmolu.yaml +++ b/fourmolu.yaml @@ -25,6 +25,8 @@ let-style: inline # Docs: https://github.com/fourmolu/fourmolu#language-extensions-dependencies-and-fixities # If you have issues with operator formatting, usually you can find the right fixity in the haddocks. fixities: - - infixl 3 <|> - - infix 4 == - - infixr 3 && +- infixr 0 $ +- infixl 3 <|> +- infixr 3 && +- infix 4 == +- infixl 4 <$>, <*> diff --git a/src/App/Fossa/VSI/Types.hs b/src/App/Fossa/VSI/Types.hs index 43cb5d9727..05f73158a2 100644 --- a/src/App/Fossa/VSI/Types.hs +++ b/src/App/Fossa/VSI/Types.hs @@ -187,7 +187,10 @@ instance FromJSON VsiExportedInferencesBody where parseJSON = withObject "VsiExportedInferencesBody" $ \obj -> do inferences <- (obj .:? "InferencesByFilePath") .!= KeyMap.empty parsedVals <- traverse parseJSON inferences - pure . VsiExportedInferencesBody . Map.mapKeys VsiFilePath . KeyMap.toMapText $ parsedVals + pure . VsiExportedInferencesBody . Map.mapKeys (VsiFilePath . stripFossaVirtual) . KeyMap.toMapText $ parsedVals + +stripFossaVirtual :: Text -> Text +stripFossaVirtual = Text.replace "!_fossa.virtual_!" "" data VsiRule = VsiRule { vsiRulePath :: VsiRulePath diff --git a/test/App/Fossa/VSI/TypesSpec.hs b/test/App/Fossa/VSI/TypesSpec.hs index 48159ab930..13422ef1d0 100644 --- a/test/App/Fossa/VSI/TypesSpec.hs +++ b/test/App/Fossa/VSI/TypesSpec.hs @@ -25,6 +25,21 @@ inferencesBody = } |] +inferencesInArchiveBody :: BS.ByteString +inferencesInArchiveBody = + [r| +{ + "InferencesByFilePath": { + "/foo/container.zip!_fossa.virtual_!/bar.h": { + "RawSha256": "YmIwMTg2NTNlOTVlY2U5M2VmMDYwMTQ3YjA0ZjZhYzRkZjhlMzFhZDc1OWFjYmExZWJmMjIwZDVjZTJlM2ZkZQ==", + "ComponentID": "0f4ba6a8-5b3f-436f-8c36-828e7375aef7", + "Locator": "git+github.com/facebook/folly$v2016.08.08.00", + "Confidence": 1 + } + } +} +|] + emptyLocatorInference :: BS.ByteString emptyLocatorInference = [r| @@ -69,6 +84,10 @@ expectedSingleInference :: VsiExportedInferencesBody expectedSingleInference = VsiExportedInferencesBody $ Map.fromList singleInference +expectedSingleInferenceInArchive :: VsiExportedInferencesBody +expectedSingleInferenceInArchive = + VsiExportedInferencesBody $ Map.fromList singleInferenceInArchive + singleInference :: [(VsiFilePath, VsiInference)] singleInference = [ @@ -77,6 +96,14 @@ singleInference = ) ] +singleInferenceInArchive :: [(VsiFilePath, VsiInference)] +singleInferenceInArchive = + [ + ( VsiFilePath "/foo/container.zip/bar.h" + , VsiInference . Just $ Locator "git" "github.com/facebook/folly" "v2016.08.08.00" + ) + ] + singleRuleExpected :: [VsiRule] singleRuleExpected = [VsiRule (VsiRulePath "/foo/") (Locator "git" "github.com/facebook/folly" "v2016.08.08.00")] @@ -124,6 +151,9 @@ vsiTypesSpec = describe "VSI Types" $ do it "Parses a VsiExportedInferencesBody" $ do let body = eitherDecode inferencesBody body `shouldBe` Right expectedSingleInference + it "Strips 'fossa virtual' from archives" $ do + let body = eitherDecode inferencesInArchiveBody + body `shouldBe` Right expectedSingleInferenceInArchive it "Accepts an empty string locator" $ do let body = eitherDecode emptyLocatorInference body `shouldBe` Right expectedEmptyLocatorInference