Skip to content

Commit 5e9448c

Browse files
authored
Merge branch 'master' into status-d-fix
2 parents 9e63fbf + 9cab5c4 commit 5e9448c

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/Srclib/Types.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ module Srclib.Types (
4141
) where
4242

4343
import Data.Aeson
44+
import Data.Char qualified as Char
4445
import Data.List.NonEmpty (NonEmpty ((:|)))
4546
import Data.List.NonEmpty qualified as NE
4647
import Data.Map (Map)
@@ -497,7 +498,10 @@ instance ToText Locator where
497498

498499
renderLocator :: Locator -> Text
499500
renderLocator 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>)
503507
projectId :: Locator -> Text

test/Srclib/TypesSpec.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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

1617
spec :: Spec
1718
spec = 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.\t9.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 =

0 commit comments

Comments
 (0)