Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore case when matching SPDX identifiers #5432

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cabal/Distribution/SPDX/LicenseExceptionId.hs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ licenseExceptionName WxWindows_exception_3_1 = "WxWindows Library Exception 3.1"

-- | Create a 'LicenseExceptionId' from a 'String'.
mkLicenseExceptionId :: String -> Maybe LicenseExceptionId
mkLicenseExceptionId s = Map.lookup s stringLookup
mkLicenseExceptionId s = Map.lookup (map toLower s) stringLookup

stringLookup :: Map String LicenseExceptionId
stringLookup = Map.fromList $ map (\i -> (licenseExceptionId i, i)) $ [minBound .. maxBound]
stringLookup = Map.fromList $ map (\i -> (map toLower (licenseExceptionId i), i)) $ [minBound .. maxBound]
4 changes: 2 additions & 2 deletions Cabal/Distribution/SPDX/LicenseId.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,7 @@ licenseIsOsiApproved ZPL_2_1 = False

-- | Create a 'LicenseId' from a 'String'.
mkLicenseId :: String -> Maybe LicenseId
mkLicenseId s = Map.lookup s stringLookup
mkLicenseId s = Map.lookup (map toLower s) stringLookup

stringLookup :: Map String LicenseId
stringLookup = Map.fromList $ map (\i -> (licenseId i, i)) $ [minBound .. maxBound]
stringLookup = Map.fromList $ map (\i -> (map toLower (licenseId i), i)) $ [minBound .. maxBound]
12 changes: 12 additions & 0 deletions Cabal/tests/UnitTests/Distribution/SPDX.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import Test.Tasty.QuickCheck
spdxTests :: [TestTree]
spdxTests =
[ testProperty "LicenseId roundtrip" licenseIdRoundtrip
, testProperty "LicenseId roundtrip (lower case)" licenseIdRoundtripLowerCase
, testProperty "LicenseExceptionId roundtrip" licenseExceptionIdRoundtrip
, testProperty "LicenseExceptionId roundtrip (lower case)" licenseExceptionIdRoundtripLowerCase
, testProperty "LicenseRef roundtrip" licenseRefRoundtrip
, testProperty "SimpleLicenseExpression roundtrip" simpleLicenseExpressionRoundtrip
, testProperty "LicenseExpression roundtrip" licenseExpressionRoundtrip
Expand All @@ -27,11 +29,21 @@ licenseIdRoundtrip x =
counterexample (prettyShow x) $
Right x === eitherParsec (prettyShow x)

licenseIdRoundtripLowerCase :: LicenseId -> Property
licenseIdRoundtripLowerCase x =
counterexample (prettyShow x) $
Right x === eitherParsec (map toLower $ prettyShow x)

licenseExceptionIdRoundtrip :: LicenseExceptionId -> Property
licenseExceptionIdRoundtrip x =
counterexample (prettyShow x) $
Right x === eitherParsec (prettyShow x)

licenseExceptionIdRoundtripLowerCase :: LicenseExceptionId -> Property
licenseExceptionIdRoundtripLowerCase x =
counterexample (prettyShow x) $
Right x === eitherParsec (map toLower $ prettyShow x)

licenseRefRoundtrip :: LicenseRef -> Property
licenseRefRoundtrip x =
counterexample (prettyShow x) $
Expand Down