@@ -37,6 +37,7 @@ import qualified Data.Map as Map
37
37
import Data.Sequence (Seq ((:<|) ))
38
38
import qualified Data.Set as Set
39
39
import qualified Data.Text as T
40
+ import qualified Data.Text.Read as T
40
41
import qualified Data.Text.Lazy as T (toStrict )
41
42
import Data.Time (LocalTime (.. ), ZonedTime (.. ), midnight , utc )
42
43
import Distribution.Parsec (eitherParsec )
@@ -420,8 +421,17 @@ onKey tbl k absent present =
420
421
421
422
isCWE :: TOML. Value -> TableParser CWE. CWEID
422
423
isCWE (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"
425
435
426
436
isString :: TOML. Value -> TableParser T. Text
427
437
isString (TOML. String txt) = pure txt
0 commit comments