diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2022-11-18 14:18:27 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2022-12-16 22:52:59 +0900 |
commit | 3e49d62bc1696a7943e4407328714e32b539b007 (patch) | |
tree | 23d1be344bf862dbd9734772ca172b671b122138 /time.c | |
parent | 635fc5f7fc88a2344118e7a156ff1b2644d0de0c (diff) | |
download | ruby-3e49d62bc1696a7943e4407328714e32b539b007.tar.gz |
[Feature #18033] Parse more strictly conformant with ISO-8601
* 4-digits or more is required as year
* Minutes and seconds parts are not ommittable
Diffstat (limited to 'time.c')
-rw-r--r-- | time.c | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -2519,8 +2519,8 @@ time_init_parse(rb_execution_context_t *ec, VALUE klass, VALUE str, VALUE zone, if (NIL_P(year)) { rb_raise(rb_eArgError, "can't parse: %+"PRIsVALUE, str); } - else if (ndigits != 2 && ndigits < 4) { - rb_raise(rb_eArgError, "year must be 2 or 4+ digits: %.*s", (int)ndigits, ptr - ndigits); + else if (ndigits < 4) { + rb_raise(rb_eArgError, "year must be 4 or more digits: %.*s", (int)ndigits, ptr - ndigits); } do { #define peekable_p(n) ((ptrdiff_t)(n) < (end - ptr)) @@ -2538,15 +2538,20 @@ time_init_parse(rb_execution_context_t *ec, VALUE klass, VALUE str, VALUE zone, if (!ISDIGIT(peekc_n(1))) break; #define nofraction(x) \ if (peek('.')) { \ - rb_raise(rb_eArgError, "fraction %s is not supported: %.*s", #x, \ + rb_raise(rb_eArgError, "fraction " #x " is not supported: %.*s", \ + (int)(ptr + 1 - time_part), time_part); \ + } +#define need_colon(x) \ + if (!peek(':')) { \ + rb_raise(rb_eArgError, "missing " #x " part: %.*s", \ (int)(ptr + 1 - time_part), time_part); \ } expect_two_digits(hour); nofraction(hour); - if (!peek(':')) break; + need_colon(min); expect_two_digits(min); nofraction(min); - if (!peek(':')) break; + need_colon(sec); expect_two_digits(sec); if (peek('.')) { ptr++; |