Skip to content

CDRIVER-5572 Allow ':' in timezone #1599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/libbson/src/bson/bson-iso8601.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ _bson_iso8601_date_parse (const char *str, int32_t len, int64_t *out, bson_error

#define DEFAULT_DATE_PARSE_ERR \
DATE_PARSE_ERR ("use ISO8601 format yyyy-mm-ddThh:mm plus timezone, either" \
" \"Z\" or like \"+0500\"")
" \"Z\" or like \"+0500\" or like \"+05:00\"")

ptr = str;

Expand Down Expand Up @@ -214,15 +214,17 @@ _bson_iso8601_date_parse (const char *str, int32_t len, int64_t *out, bson_error
int32_t tz_hour;
int32_t tz_min;

if (tz_len != 5 || !digits_only (tz_ptr + 1, 4)) {
if ((tz_len != 5 || !digits_only (tz_ptr + 1, 4)) &&
(tz_len != 6 || !digits_only (tz_ptr + 1, 2) || tz_ptr[3] != ':' || !digits_only (tz_ptr + 4, 2))) {
DATE_PARSE_ERR ("could not parse timezone");
}

if (!parse_num (tz_ptr + 1, 2, -1, -23, 23, &tz_hour)) {
DATE_PARSE_ERR ("timezone hour must be at most 23");
}

if (!parse_num (tz_ptr + 3, 2, -1, 0, 59, &tz_min)) {
int32_t tz_min_offset = tz_ptr[3] == ':' ? 1 : 0;
if (!parse_num (tz_ptr + 3 + tz_min_offset, 2, -1, 0, 59, &tz_min)) {
DATE_PARSE_ERR ("timezone minute must be at most 59");
}

Expand Down
2 changes: 2 additions & 0 deletions src/libbson/tests/test-iso8601.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ test_bson_iso8601_utc (void)
test_date_io ("1970-01-01T00:00:00.000Z", "1970-01-01T00:00:00Z", 0ULL);
test_date_rt ("1970-06-30T01:06:40.981Z", 15556000981ULL);
test_date ("1970-01-01T00:00:00.000+0100", -3600LL * 1000);
test_date ("1970-01-01T00:00:00.000+01:00", -3600LL * 1000);

if (!is_time_t_small) {
test_date_rt ("2058-02-20T18:29:11.100Z", 2781455351100ULL);
Expand Down Expand Up @@ -115,6 +116,7 @@ test_bson_iso8601_local (void)
test_date_io ("1971-02-03T09:16:06.7+0511", "1971-02-03T04:05:06.700Z", 34401906700ULL);
test_date_io ("1971-02-03T09:16:06+0511", "1971-02-03T04:05:06Z", 34401906000ULL);
test_date_io ("1971-02-03T09:16+0511", "1971-02-03T04:05:00Z", 34401900000ULL);
test_date_io ("1971-02-03T09:16+05:11", "1971-02-03T04:05:00Z", 34401900000ULL);
test_date_io ("1970-01-01T00:00:00.000Z", "1970-01-01T00:00:00Z", 0ULL);
test_date_rt ("1970-06-30T01:06:40.981Z", 15556000981ULL);
test_date_io ("1970-06-29T21:06:40.981-0400", "1970-06-30T01:06:40.981Z", 15556000981ULL);
Expand Down
2 changes: 1 addition & 1 deletion src/libbson/tests/test-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -2319,7 +2319,7 @@ test_bson_json_date (void)
test_bson_json_date_check ("{ \"dt\" : { \"$date\" : \"1970-01-01T00:00:00.000Z\" } }", 0);
test_bson_json_date_check ("{ \"dt\" : { \"$date\" : \"1969-12-31T16:00:00.000-0800\" } }", 0);

test_bson_json_date_error ("{ \"dt\" : { \"$date\" : \"1970-01-01T01:00:00.000+01:00\" } }", "Could not parse");
test_bson_json_date_check ("{ \"dt\" : { \"$date\" : \"1970-01-01T01:00:00.000+01:00\" } }", 0);
test_bson_json_date_error ("{ \"dt\" : { \"$date\" : \"1970-01-01T01:30:\" } }",
"reached end of date while looking for seconds");
test_bson_json_date_error ("{ \"dt\" : { \"$date\" : \"1970-01-01T01:00:+01:00\" } }", "seconds is required");
Expand Down