Skip to content

Commit bdafa35

Browse files
committed
Fix bug where freeform fields can be misinterpreted as data
1 parent a95608f commit bdafa35

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/Hie/Cabal/Parser.hs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,34 @@ data Component
3232
parsePackage' :: Text -> Either String Package
3333
parsePackage' = parseOnly parsePackage
3434

35+
-- Skip over entire fields that are known to be free-form. Ensures lines that
36+
-- look like the beginning of sections/stanzas are not inadvertently intepreted
37+
-- as such.
38+
-- List gathered by searching "free text field" in:
39+
-- https://cabal.readthedocs.io/en/3.4/buildinfo-fields-reference.html
40+
-- May be subject to change across Cabal versions.
41+
skipFreeformField :: Parser ()
42+
skipFreeformField =
43+
choice $ flip (field 0) skipBlock <$>
44+
[ "author"
45+
, "bug-reports"
46+
, "category"
47+
, "copyright"
48+
, "description"
49+
, "homepage"
50+
, "maintainer"
51+
, "package-url"
52+
, "stability"
53+
, "synopsis"
54+
]
55+
3556
parsePackage :: Parser Package
3657
parsePackage =
3758
( do
3859
n <- field 0 "name" $ const parseString
3960
(Package _ t) <- parsePackage
4061
pure $ Package n t
41-
)
62+
) <|> (skipFreeformField >> parsePackage)
4263
<|> ( do
4364
h <- parseComponent 0
4465
(Package n t) <- parsePackage

0 commit comments

Comments
 (0)