Skip to content

Commit d611da5

Browse files
committed
Merge remote-tracking branch 'nielsdos/fix-php-gh-17159' into v2022
2 parents b5528b3 + c2abe37 commit d611da5

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

parse_date.re

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,10 +939,12 @@ timelib_long timelib_parse_zone(const char **ptr, int *dst, timelib_time *t, int
939939
{
940940
timelib_tzinfo *res;
941941
timelib_long retval = 0;
942+
size_t paren_count = 0;
942943

943944
*tz_not_found = 0;
944945

945946
while (**ptr == ' ' || **ptr == '\t' || **ptr == '(') {
947+
paren_count += **ptr == '(';
946948
++*ptr;
947949
}
948950
if ((*ptr)[0] == 'G' && (*ptr)[1] == 'M' && (*ptr)[2] == 'T' && ((*ptr)[3] == '+' || (*ptr)[3] == '-')) {
@@ -991,8 +993,9 @@ timelib_long timelib_parse_zone(const char **ptr, int *dst, timelib_time *t, int
991993
*tz_not_found = (found == 0);
992994
retval = offset;
993995
}
994-
while (**ptr == ')') {
996+
while (paren_count > 0 && **ptr == ')') {
995997
++*ptr;
998+
paren_count--;
996999
}
9971000
return retval;
9981001
}

tests/c/parse_tz.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,20 @@ TEST(parse_tz, etc_gmt_2)
136136
timelib_tzinfo_dtor(t->tz_info);
137137
timelib_time_dtor(t);
138138
}
139+
140+
TEST(parse_tz, parentheses)
141+
{
142+
timelib_time *t = timelib_time_ctor();
143+
const char *tz_name = "((UTC)))";
144+
int is_dst;
145+
int tz_not_found;
146+
147+
timelib_parse_zone(&tz_name, &is_dst, t, &tz_not_found, timelib_builtin_db(), test_date_parse_tzfile);
148+
149+
CHECK(t->tz_info != NULL);
150+
STRCMP_EQUAL(t->tz_info->name, "UTC");
151+
BYTES_EQUAL(*tz_name, ')');
152+
153+
timelib_tzinfo_dtor(t->tz_info);
154+
timelib_time_dtor(t);
155+
}

0 commit comments

Comments
 (0)