@@ -37,6 +37,7 @@ import qualified Data.Map as Map
3737import Data.Sequence (Seq ((:<|) ))
3838import qualified Data.Set as Set
3939import qualified Data.Text as T
40+ import qualified Data.Text.Read as T
4041import qualified Data.Text.Lazy as T (toStrict )
4142import Data.Time (LocalTime (.. ), ZonedTime (.. ), midnight , utc )
4243import Distribution.Parsec (eitherParsec )
@@ -420,8 +421,17 @@ onKey tbl k absent present =
420421
421422isCWE :: TOML. Value -> TableParser CWE. CWEID
422423isCWE (TOML. Integer i) | Just cwe <- CWE. mkCWEID i, Map. member cwe CWE. cweNames = pure cwe
423- isCWE (TOML. String txt) | Just cwe <- Map. lookup txt CWE. cweIds = pure cwe
424- isCWE other = throwError $ InvalidFormat " Integer" (describeValue other) " 42"
424+ isCWE (TOML. String txt) = case T. breakOn " :" txt of
425+ (numTxt, name) -> case T. decimal numTxt of
426+ Right (num, " " ) -> do
427+ cwe <- isCWE (TOML. Integer num)
428+ case T. strip (T. drop 1 name) of
429+ " " -> pure cwe
430+ expectedName -> case Map. lookup cwe CWE. cweNames of
431+ Just cweName | expectedName == cweName -> pure cwe
432+ _ -> error (" bad name: " <> show cwe <> " , " <> show expectedName)
433+ _ -> error (" bad num: " <> show numTxt)
434+ isCWE other = throwError $ InvalidFormat " CWE ID" (describeValue other) " 42"
425435
426436isString :: TOML. Value -> TableParser T. Text
427437isString (TOML. String txt) = pure txt
0 commit comments