diff --git a/hledger-lib/Ledger/Dates.hs b/hledger-lib/Ledger/Dates.hs index c62773cd1..eb7c054fa 100644 --- a/hledger-lib/Ledger/Dates.hs +++ b/hledger-lib/Ledger/Dates.hs @@ -262,11 +262,10 @@ ymd = do y <- many1 digit datesepchar m <- try (count 2 digit) <|> count 1 digit - guard (read m >= 1 && (read m <= 12)) - -- when (read m < 1 || (read m > 12)) $ fail "bad month number specified" + when (read m < 1 || (read m > 12)) $ error $ "bad month number: " ++ m datesepchar d <- try (count 2 digit) <|> count 1 digit - when (read d < 1 || (read d > 31)) $ fail "bad day number specified" + when (read d < 1 || (read d > 31)) $ error $ "bad day number: " ++ d return $ (y,m,d) ym :: GenParser Char st SmartDate diff --git a/tests/parse-dates.test b/tests/parse-dates.test new file mode 100644 index 000000000..59dc4b6f4 --- /dev/null +++ b/tests/parse-dates.test @@ -0,0 +1,15 @@ +# dates with bad month or day numbers should be rejected +-f- print +<<< +2010/31/12 x + a 1 + b +>>>2 /bad month number: 31/ +>>>= 1 +-f- print +<<< +2010/12/32 x + a 1 + b +>>>2 /bad day number: 32/ +>>>= 1