diff --git a/NEWS.md b/NEWS.md index 8f50d27f..1cf497be 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # readr (development version) +* Invalid date formats no longer can potentially crash R (#1151) + # readr 1.4.0 ## Breaking changes diff --git a/src/DateTimeParser.h b/src/DateTimeParser.h index fdd38621..b0f22af3 100644 --- a/src/DateTimeParser.h +++ b/src/DateTimeParser.h @@ -285,7 +285,7 @@ class DateTimeParser { break; default: - cpp11::stop("Unsupported format %%%s", *formatItr); + cpp11::stop("Unsupported format %%%s", formatItr); } } diff --git a/tests/testthat/test-parsing-datetime.R b/tests/testthat/test-parsing-datetime.R index 2863a8cd..b78987e2 100644 --- a/tests/testthat/test-parsing-datetime.R +++ b/tests/testthat/test-parsing-datetime.R @@ -263,3 +263,7 @@ test_that("must have either two - or none", { expect_equal(guess_parser("200010-10"), "character") expect_equal(guess_parser("20001010"), "double") }) + +test_that("Invalid formats error", { + expect_error(parse_date("2020-11-17", "%%Y-%m-%d"), "Unsupported format %%Y-%m-%d") +})