File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ module Srclib.Types (
4141) where
4242
4343import Data.Aeson
44+ import Data.Char qualified as Char
4445import Data.List.NonEmpty (NonEmpty ((:|) ))
4546import Data.List.NonEmpty qualified as NE
4647import Data.Map (Map )
@@ -497,7 +498,10 @@ instance ToText Locator where
497498
498499renderLocator :: Locator -> Text
499500renderLocator Locator {.. } =
500- locatorFetcher <> " +" <> locatorProject <> " $" <> fromMaybe " " locatorRevision
501+ stripNonPrintable $
502+ locatorFetcher <> " +" <> locatorProject <> " $" <> fromMaybe " " locatorRevision
503+ where
504+ stripNonPrintable = Text. filter Char. isPrint
501505
502506-- The projectId is the full locator of the project. E.g. custom+123/someProject (<fetcher>+<orgId>/<project-name>)
503507projectId :: Locator -> Text
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import Srclib.Types (
77 SourceUnit (.. ),
88 SourceUnitBuild (.. ),
99 SourceUnitDependency (.. ),
10+ renderLocator ,
1011 toProjectLocator ,
1112 translateSourceUnitLocators ,
1213 )
@@ -15,6 +16,11 @@ import Types (GraphBreadth (Complete))
1516
1617spec :: Spec
1718spec = do
19+ describe " renderLocator" $ do
20+ it " should strip non-printable characters such as NUL bytes" $ do
21+ let locator = Locator " go" " github.com/gin-gonic\NUL /gin" (Just " v1.\t 9.1\DEL " )
22+ renderLocator locator `shouldBe` " go+github.com/gin-gonic/gin$v1.9.1"
23+
1824 describe " translateSourceUnitLocators" $ do
1925 -- Helper to create a simple translation function from a map (for backward compatibility in tests)
2026 let simpleTranslate translationMap loc =
You can’t perform that action at this time.
0 commit comments