summaryrefslogtreecommitdiff
path: root/upb/json
diff options
context:
space:
mode:
authorPaul Yang <TeBoring@users.noreply.github.com>2018-09-21 11:07:21 -0700
committerGitHub <noreply@github.com>2018-09-21 11:07:21 -0700
commitb258ae323503d93997b661df1309ff339bd8341d (patch)
treefa6ed780df7066b092c2a8fb10d86a10b831be2f /upb/json
parent706ffdbc658e00fdf0d03715c8306eb7e7b7e963 (diff)
Fix mac use local timezone for strptime by default. (#127)
* Fix mac use local timezone for strptime by default. * Fix comments * Check len == UPB_TIMESTAMP_BASE_SIZE * Fix comment
Diffstat (limited to 'upb/json')
-rw-r--r--upb/json/parser.c122
-rw-r--r--upb/json/parser.rl10
2 files changed, 74 insertions, 58 deletions
diff --git a/upb/json/parser.c b/upb/json/parser.c
index 204e379..10242aa 100644
--- a/upb/json/parser.c
+++ b/upb/json/parser.c
@@ -1261,18 +1261,26 @@ static void start_timestamp_base(upb_json_parser *p, const char *ptr) {
capture_begin(p, ptr);
}
+#define UPB_TIMESTAMP_BASE_SIZE 19
+
static bool end_timestamp_base(upb_json_parser *p, const char *ptr) {
size_t len;
const char *buf;
+ /* 3 for GMT and 1 for ending 0 */
+ char timestamp_buf[UPB_TIMESTAMP_BASE_SIZE + 4];
if (!capture_end(p, ptr)) {
return false;
}
buf = accumulate_getptr(p, &len);
+ UPB_ASSERT(len == UPB_TIMESTAMP_BASE_SIZE);
+ memcpy(timestamp_buf, buf, UPB_TIMESTAMP_BASE_SIZE);
+ memcpy(timestamp_buf + UPB_TIMESTAMP_BASE_SIZE, "GMT", 3);
+ timestamp_buf[UPB_TIMESTAMP_BASE_SIZE + 3] = 0;
/* Parse seconds */
- if (strptime(buf, "%FT%H:%M:%S", &p->tm) == NULL) {
+ if (strptime(timestamp_buf, "%FT%H:%M:%S%Z", &p->tm) == NULL) {
upb_status_seterrf(&p->status, "error parsing timestamp: %s", buf);
upb_env_reporterror(p->env, &p->status);
return false;
@@ -1967,11 +1975,11 @@ static bool is_string_wrapper_object(upb_json_parser *p) {
* final state once, when the closing '"' is seen. */
-#line 2106 "upb/json/parser.rl"
+#line 2114 "upb/json/parser.rl"
-#line 1975 "upb/json/parser.c"
+#line 1983 "upb/json/parser.c"
static const char _json_actions[] = {
0, 1, 0, 1, 1, 1, 3, 1,
4, 1, 6, 1, 7, 1, 8, 1,
@@ -2222,7 +2230,7 @@ static const int json_en_value_machine = 76;
static const int json_en_main = 1;
-#line 2109 "upb/json/parser.rl"
+#line 2117 "upb/json/parser.rl"
size_t parse(void *closure, const void *hd, const char *buf, size_t size,
const upb_bufhandle *handle) {
@@ -2245,7 +2253,7 @@ size_t parse(void *closure, const void *hd, const char *buf, size_t size,
capture_resume(parser, buf);
-#line 2249 "upb/json/parser.c"
+#line 2257 "upb/json/parser.c"
{
int _klen;
unsigned int _trans;
@@ -2320,83 +2328,83 @@ _match:
switch ( *_acts++ )
{
case 1:
-#line 1980 "upb/json/parser.rl"
+#line 1988 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
case 2:
-#line 1982 "upb/json/parser.rl"
+#line 1990 "upb/json/parser.rl"
{ p--; {stack[top++] = cs; cs = 24; goto _again;} }
break;
case 3:
-#line 1986 "upb/json/parser.rl"
+#line 1994 "upb/json/parser.rl"
{ start_text(parser, p); }
break;
case 4:
-#line 1987 "upb/json/parser.rl"
+#line 1995 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_text(parser, p)); }
break;
case 5:
-#line 1993 "upb/json/parser.rl"
+#line 2001 "upb/json/parser.rl"
{ start_hex(parser); }
break;
case 6:
-#line 1994 "upb/json/parser.rl"
+#line 2002 "upb/json/parser.rl"
{ hexdigit(parser, p); }
break;
case 7:
-#line 1995 "upb/json/parser.rl"
+#line 2003 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_hex(parser)); }
break;
case 8:
-#line 2001 "upb/json/parser.rl"
+#line 2009 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(escape(parser, p)); }
break;
case 9:
-#line 2007 "upb/json/parser.rl"
+#line 2015 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
case 10:
-#line 2019 "upb/json/parser.rl"
+#line 2027 "upb/json/parser.rl"
{ start_duration_base(parser, p); }
break;
case 11:
-#line 2020 "upb/json/parser.rl"
+#line 2028 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_duration_base(parser, p)); }
break;
case 12:
-#line 2022 "upb/json/parser.rl"
+#line 2030 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
case 13:
-#line 2027 "upb/json/parser.rl"
+#line 2035 "upb/json/parser.rl"
{ start_timestamp_base(parser, p); }
break;
case 14:
-#line 2028 "upb/json/parser.rl"
+#line 2036 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_timestamp_base(parser, p)); }
break;
case 15:
-#line 2030 "upb/json/parser.rl"
+#line 2038 "upb/json/parser.rl"
{ start_timestamp_fraction(parser, p); }
break;
case 16:
-#line 2031 "upb/json/parser.rl"
+#line 2039 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_timestamp_fraction(parser, p)); }
break;
case 17:
-#line 2033 "upb/json/parser.rl"
+#line 2041 "upb/json/parser.rl"
{ start_timestamp_zone(parser, p); }
break;
case 18:
-#line 2034 "upb/json/parser.rl"
+#line 2042 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_timestamp_zone(parser, p)); }
break;
case 19:
-#line 2036 "upb/json/parser.rl"
+#line 2044 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
case 20:
-#line 2041 "upb/json/parser.rl"
+#line 2049 "upb/json/parser.rl"
{
if (is_wellknown_msg(parser, UPB_WELLKNOWN_TIMESTAMP)) {
{stack[top++] = cs; cs = 48; goto _again;}
@@ -2408,78 +2416,78 @@ _match:
}
break;
case 21:
-#line 2052 "upb/json/parser.rl"
+#line 2060 "upb/json/parser.rl"
{ p--; {stack[top++] = cs; cs = 76; goto _again;} }
break;
case 22:
-#line 2057 "upb/json/parser.rl"
+#line 2065 "upb/json/parser.rl"
{ start_member(parser); }
break;
case 23:
-#line 2058 "upb/json/parser.rl"
+#line 2066 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_membername(parser)); }
break;
case 24:
-#line 2061 "upb/json/parser.rl"
+#line 2069 "upb/json/parser.rl"
{ end_member(parser); }
break;
case 25:
-#line 2067 "upb/json/parser.rl"
+#line 2075 "upb/json/parser.rl"
{ start_object(parser); }
break;
case 26:
-#line 2070 "upb/json/parser.rl"
+#line 2078 "upb/json/parser.rl"
{ end_object(parser); }
break;
case 27:
-#line 2076 "upb/json/parser.rl"
+#line 2084 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_array(parser)); }
break;
case 28:
-#line 2080 "upb/json/parser.rl"
+#line 2088 "upb/json/parser.rl"
{ end_array(parser); }
break;
case 29:
-#line 2085 "upb/json/parser.rl"
+#line 2093 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_number(parser, p)); }
break;
case 30:
-#line 2086 "upb/json/parser.rl"
+#line 2094 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_number(parser, p)); }
break;
case 31:
-#line 2088 "upb/json/parser.rl"
+#line 2096 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_stringval(parser)); }
break;
case 32:
-#line 2089 "upb/json/parser.rl"
+#line 2097 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_stringval(parser)); }
break;
case 33:
-#line 2091 "upb/json/parser.rl"
+#line 2099 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, true)); }
break;
case 34:
-#line 2093 "upb/json/parser.rl"
+#line 2101 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, false)); }
break;
case 35:
-#line 2095 "upb/json/parser.rl"
+#line 2103 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_null(parser)); }
break;
case 36:
-#line 2097 "upb/json/parser.rl"
+#line 2105 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_subobject_full(parser)); }
break;
case 37:
-#line 2098 "upb/json/parser.rl"
+#line 2106 "upb/json/parser.rl"
{ end_subobject_full(parser); }
break;
case 38:
-#line 2103 "upb/json/parser.rl"
+#line 2111 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
-#line 2483 "upb/json/parser.c"
+#line 2491 "upb/json/parser.c"
}
}
@@ -2496,34 +2504,34 @@ _again:
while ( __nacts-- > 0 ) {
switch ( *__acts++ ) {
case 0:
-#line 1978 "upb/json/parser.rl"
+#line 1986 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
case 26:
-#line 2070 "upb/json/parser.rl"
+#line 2078 "upb/json/parser.rl"
{ end_object(parser); }
break;
case 30:
-#line 2086 "upb/json/parser.rl"
+#line 2094 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_number(parser, p)); }
break;
case 33:
-#line 2091 "upb/json/parser.rl"
+#line 2099 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, true)); }
break;
case 34:
-#line 2093 "upb/json/parser.rl"
+#line 2101 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, false)); }
break;
case 35:
-#line 2095 "upb/json/parser.rl"
+#line 2103 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_null(parser)); }
break;
case 37:
-#line 2098 "upb/json/parser.rl"
+#line 2106 "upb/json/parser.rl"
{ end_subobject_full(parser); }
break;
-#line 2527 "upb/json/parser.c"
+#line 2535 "upb/json/parser.c"
}
}
}
@@ -2531,7 +2539,7 @@ _again:
_out: {}
}
-#line 2131 "upb/json/parser.rl"
+#line 2139 "upb/json/parser.rl"
if (p != pe) {
upb_status_seterrf(&parser->status, "Parse error at '%.*s'\n", pe - p, p);
@@ -2563,9 +2571,9 @@ bool end(void *closure, const void *hd) {
parse(parser, hd, &eof_ch, 0, NULL);
return parser->current_state >=
-#line 2567 "upb/json/parser.c"
+#line 2575 "upb/json/parser.c"
105
-#line 2161 "upb/json/parser.rl"
+#line 2169 "upb/json/parser.rl"
;
}
@@ -2580,13 +2588,13 @@ static void json_parser_reset(upb_json_parser *p) {
/* Emit Ragel initialization of the parser. */
-#line 2584 "upb/json/parser.c"
+#line 2592 "upb/json/parser.c"
{
cs = json_start;
top = 0;
}
-#line 2175 "upb/json/parser.rl"
+#line 2183 "upb/json/parser.rl"
p->current_state = cs;
p->parser_top = top;
accumulate_clear(p);
diff --git a/upb/json/parser.rl b/upb/json/parser.rl
index 217caef..8e6caa9 100644
--- a/upb/json/parser.rl
+++ b/upb/json/parser.rl
@@ -1259,18 +1259,26 @@ static void start_timestamp_base(upb_json_parser *p, const char *ptr) {
capture_begin(p, ptr);
}
+#define UPB_TIMESTAMP_BASE_SIZE 19
+
static bool end_timestamp_base(upb_json_parser *p, const char *ptr) {
size_t len;
const char *buf;
+ /* 3 for GMT and 1 for ending 0 */
+ char timestamp_buf[UPB_TIMESTAMP_BASE_SIZE + 4];
if (!capture_end(p, ptr)) {
return false;
}
buf = accumulate_getptr(p, &len);
+ UPB_ASSERT(len == UPB_TIMESTAMP_BASE_SIZE);
+ memcpy(timestamp_buf, buf, UPB_TIMESTAMP_BASE_SIZE);
+ memcpy(timestamp_buf + UPB_TIMESTAMP_BASE_SIZE, "GMT", 3);
+ timestamp_buf[UPB_TIMESTAMP_BASE_SIZE + 3] = 0;
/* Parse seconds */
- if (strptime(buf, "%FT%H:%M:%S", &p->tm) == NULL) {
+ if (strptime(timestamp_buf, "%FT%H:%M:%S%Z", &p->tm) == NULL) {
upb_status_seterrf(&p->status, "error parsing timestamp: %s", buf);
upb_env_reporterror(p->env, &p->status);
return false;
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback