@@ -114,11 +114,11 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
114114 int format_len ,
115115 FormatRequirement format_requirement ,
116116 double threshold ) {
117+ const char * substr = NULL ;
117118 if (len < 0 || format_len < 0 )
118119 goto parse_error ;
119120 int year_leap = 0 ;
120121 int i , numdigits ;
121- const char * substr ;
122122 int sublen ;
123123 NPY_DATETIMEUNIT bestunit = NPY_FR_GENERIC ;
124124 DatetimePartParseResult comparison ;
@@ -742,28 +742,38 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
742742
743743 /* Invalidates the component if there is more than 2 digits */
744744 if (sublen > 0 ) {
745- int still_more = 1 ;
746- if (!isdigit (substr [0 ])) {
747- still_more = 0 ;
745+ int has_sep = 0 ;
746+ int j = 0 ;
747+ for (j = 0 ; j < (sublen > 2 ? 2 : sublen ); ++ j ) {
748+ char c = substr [j ];
749+ if (c == ':' ) {
750+ has_sep = 1 ;
751+ }
752+ if (has_sep || !isdigit (c )) {
753+ break ;
754+ }
748755 }
749- if (still_more ) {
756+ if (has_sep && j != 0 ) {
750757 invalid_components ++ ;
751- while (sublen > 0 && isdigit (substr [0 ])) {
752- substr ++ ;
753- sublen -- ;
754- }
758+ substr += j ;
759+ sublen -= j ;
755760 if (sublen == 0 ) {
756761 goto finish ;
757762 }
758763 goto hour_sep ;
759764 }
760- }
761-
762- if (out -> hour >= 24 ) {
763- invalid_components ++ ;
764- goto hour_sep ;
765+ if (!has_sep && sublen < 4 ) {
766+ invalid_components ++ ;
767+ substr += sublen ;
768+ sublen = 0 ;
769+ goto finish ;
770+ }
765771 }
766772 }
773+ if (out -> hour >= 24 ) {
774+ invalid_components ++ ;
775+ goto hour_sep ;
776+ }
767777
768778hour_sep :
769779 /* Next character must be a ':' or the end of the string */
@@ -884,21 +894,32 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
884894
885895 /* Invalidates the component if there is more than 2 digits */
886896 if (sublen > 0 ) {
887- int still_more = 1 ;
888- if (!isdigit (substr [0 ])) {
889- still_more = 0 ;
897+ int has_sep = 0 ;
898+ int j = 0 ;
899+ for (j = 0 ; j < (sublen > 2 ? 2 : sublen ); ++ j ) {
900+ char c = substr [j ];
901+ if (c == ':' ) {
902+ has_sep = 1 ;
903+ }
904+ if (has_sep || !isdigit (c )) {
905+ break ;
906+ }
890907 }
891- if (still_more ) {
908+ if (has_sep && j != 0 ) {
892909 invalid_components ++ ;
893- while (sublen > 0 && isdigit (substr [0 ])) {
894- substr ++ ;
895- sublen -- ;
896- }
910+ substr += j ;
911+ sublen -= j ;
897912 if (sublen == 0 ) {
898913 goto finish ;
899914 }
900915 goto minute_sep ;
901916 }
917+ if (!has_sep && sublen < 2 ) {
918+ invalid_components ++ ;
919+ substr += sublen ;
920+ sublen = 0 ;
921+ goto finish ;
922+ }
902923 }
903924
904925 if (out -> min >= 60 ) {
0 commit comments