summaryrefslogtreecommitdiff
path: root/upb/json/parser.c
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2016-04-14 16:28:47 -0700
committerJoshua Haberman <jhaberman@gmail.com>2016-04-14 16:28:47 -0700
commit89197b9358c127e41dd9f428578783ec09a94d82 (patch)
treea970d947ecfd7dba9df92b92982ae08d5f2dd9a2 /upb/json/parser.c
parent534b5c98baf02b2101d25917d46a1605906a6c53 (diff)
JSON parser: always accept both name variants, flag controls which we generate.
* JSON parser: always accept both name variants, flag controls which we generate. My previous commit was based on wrong information about the proto3 JSON spec. It turns out we need to accept both field name formats all the time, and a runtime flag should control which we generate. * Documented the preserve_proto_fieldnames option. * Fix bugs in PR.
Diffstat (limited to 'upb/json/parser.c')
-rw-r--r--upb/json/parser.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/upb/json/parser.c b/upb/json/parser.c
index e1a334d..1662f1a 100644
--- a/upb/json/parser.c
+++ b/upb/json/parser.c
@@ -1527,7 +1527,7 @@ _again:
#line 1270 "upb/json/parser.rl"
if (p != pe) {
- upb_status_seterrf(&parser->status, "Parse error at %s\n", p);
+ upb_status_seterrf(&parser->status, "Parse error at '%.*s'\n", p, pe - p);
upb_env_reporterror(parser->env, &parser->status);
} else {
capture_suspend(parser, &p);
@@ -1628,6 +1628,7 @@ static void add_jsonname_table(upb_json_parsermethod *m, const upb_msgdef* md) {
upb_msg_field_next(&i)) {
const upb_fielddef *f = upb_msg_iter_field(&i);
+ /* Add an entry for the JSON name. */
size_t field_len = upb_fielddef_getjsonname(f, buf, len);
if (field_len > len) {
size_t len2;
@@ -1638,10 +1639,10 @@ static void add_jsonname_table(upb_json_parsermethod *m, const upb_msgdef* md) {
}
upb_strtable_insert(t, buf, upb_value_constptr(f));
- if (getenv("UPB_JSON_ACCEPT_LEGACY_FIELD_NAMES")) {
- /* Temporary code to help people migrate if they were depending on the
- * old, non-proto3-json-compliant field names. In this case we
- * recognize both old names and new names. */
+ if (strcmp(buf, upb_fielddef_name(f)) != 0) {
+ /* Since the JSON name is different from the regular field name, add an
+ * entry for the raw name (compliant proto3 JSON parsers must accept
+ * both). */
upb_strtable_insert(t, upb_fielddef_name(f), upb_value_constptr(f));
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback