Skip to content

Commit

Permalink
Merge pull request #6370 from commercialhaskell/fix6369
Browse files Browse the repository at this point in the history
Fix #6369 Accept package names, in fact, acceptable to Cabal
  • Loading branch information
mpilgrem authored Dec 10, 2023
2 parents a3083e7 + d8209e9 commit fe7eb6f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Bug fixes:
* Fix the `Curator` instance of `ToJSON`, as regards `expect-haddock-failure`.
* Better error message if a `resolver:` or `snapshot:` value is, in error, a
YAML number.
* Stack accepts all package names that are, in fact, acceptable to Cabal.

## v2.13.1 - 2023-09-29

Expand Down
14 changes: 10 additions & 4 deletions src/Stack/Types/GhcPkgId.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE NoImplicitPrelude #-}

-- | A ghc-pkg id.

Expand All @@ -12,13 +12,14 @@ module Stack.Types.GhcPkgId

import Data.Aeson.Types ( FromJSON (..), ToJSON (..), withText )
import Data.Attoparsec.Text
( Parser, choice, digit, endOfInput, letter, many1, parseOnly
( Parser, (<?>), choice, endOfInput, many1, parseOnly
, satisfy
)
import Data.Char ( isAlphaNum )
import qualified Data.Text as T
import Database.Persist.Sql ( PersistField, PersistFieldSql )
import Prelude ( Read (..) )
import Stack.Prelude
import Text.Read ( Read (..) )

-- | A parse fail.
newtype GhcPkgIdParseFail
Expand Down Expand Up @@ -70,7 +71,12 @@ ghcPkgIdParser :: Parser GhcPkgId
ghcPkgIdParser =
let elements = "_.-" :: String
in GhcPkgId . T.pack <$>
many1 (choice [digit, letter, satisfy (`elem` elements)])
many1 (choice [alphaNum, satisfy (`elem` elements)])

-- | Parse an alphanumerical character, as recognised by `isAlphaNum`.
alphaNum :: Parser Char
alphaNum = satisfy isAlphaNum <?> "alphanumeric"
{-# INLINE alphaNum #-}

-- | Get a string representation of GHC package id.
ghcPkgIdString :: GhcPkgId -> String
Expand Down
16 changes: 11 additions & 5 deletions src/Stack/Types/PackageName.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ packageNameArgument =
case parsePackageName s of
Just x -> Right x
Nothing -> Left $ unlines
[ "Expected valid package name, but got: " ++ s
, "Package names consist of one or more alphanumeric words separated \
\by hyphens."
, "To avoid ambiguity with version numbers, each of these words must \
\contain at least one letter."
[ "Expected a package name acceptable to Cabal, but got: " ++ s ++ "\n"
, "An acceptable package name comprises an alphanumeric 'word'; or \
\two or more"
, "such words, with the words separated by a hyphen/minus character ('-'). A \
\word"
, "cannot be comprised only of the characters '0' to '9'. \n"
, "An alphanumeric character is one in one of the Unicode Letter \
\categories"
, "(Lu (uppercase), Ll (lowercase), Lt (titlecase), Lm (modifier), or \
\Lo (other))"
, "or Number categories (Nd (decimal), Nl (letter), or No (other))."
]

0 comments on commit fe7eb6f

Please sign in to comment.