diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c index 5527265f0c..e570089ed8 100644 --- a/php/ext/google/protobuf/php-upb.c +++ b/php/ext/google/protobuf/php-upb.c @@ -15126,7 +15126,10 @@ void _upb_MessageDef_InsertField(upb_DefBuilder* ctx, upb_MessageDef* m, _upb_MessageDef_Insert(m, shortname, shortnamelen, field_v, ctx->arena); if (!ok) _upb_DefBuilder_OomErr(ctx); - if (strcmp(shortname, json_name) != 0 && + bool skip_json_conflicts = + UPB_DESC(MessageOptions_deprecated_legacy_json_field_conflicts)( + upb_MessageDef_Options(m)); + if (!skip_json_conflicts && strcmp(shortname, json_name) != 0 && UPB_DESC(FeatureSet_json_format)(m->resolved_features) == UPB_DESC(FeatureSet_ALLOW) && upb_strtable_lookup(&m->ntof, json_name, &v)) { @@ -15136,14 +15139,16 @@ void _upb_MessageDef_InsertField(upb_DefBuilder* ctx, upb_MessageDef* m, } if (upb_strtable_lookup(&m->jtof, json_name, &v)) { - _upb_DefBuilder_Errf(ctx, "duplicate json_name (%s)", json_name); + if (!skip_json_conflicts) { + _upb_DefBuilder_Errf(ctx, "duplicate json_name (%s)", json_name); + } + } else { + const size_t json_size = strlen(json_name); + ok = upb_strtable_insert(&m->jtof, json_name, json_size, + upb_value_constptr(f), ctx->arena); + if (!ok) _upb_DefBuilder_OomErr(ctx); } - const size_t json_size = strlen(json_name); - ok = upb_strtable_insert(&m->jtof, json_name, json_size, - upb_value_constptr(f), ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - if (upb_inttable_lookup(&m->itof, field_number, NULL)) { _upb_DefBuilder_Errf(ctx, "duplicate field number (%u)", field_number); } diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c index bbbd7fc9bb..7eacee0490 100644 --- a/ruby/ext/google/protobuf_c/ruby-upb.c +++ b/ruby/ext/google/protobuf_c/ruby-upb.c @@ -14640,7 +14640,10 @@ void _upb_MessageDef_InsertField(upb_DefBuilder* ctx, upb_MessageDef* m, _upb_MessageDef_Insert(m, shortname, shortnamelen, field_v, ctx->arena); if (!ok) _upb_DefBuilder_OomErr(ctx); - if (strcmp(shortname, json_name) != 0 && + bool skip_json_conflicts = + UPB_DESC(MessageOptions_deprecated_legacy_json_field_conflicts)( + upb_MessageDef_Options(m)); + if (!skip_json_conflicts && strcmp(shortname, json_name) != 0 && UPB_DESC(FeatureSet_json_format)(m->resolved_features) == UPB_DESC(FeatureSet_ALLOW) && upb_strtable_lookup(&m->ntof, json_name, &v)) { @@ -14650,14 +14653,16 @@ void _upb_MessageDef_InsertField(upb_DefBuilder* ctx, upb_MessageDef* m, } if (upb_strtable_lookup(&m->jtof, json_name, &v)) { - _upb_DefBuilder_Errf(ctx, "duplicate json_name (%s)", json_name); + if (!skip_json_conflicts) { + _upb_DefBuilder_Errf(ctx, "duplicate json_name (%s)", json_name); + } + } else { + const size_t json_size = strlen(json_name); + ok = upb_strtable_insert(&m->jtof, json_name, json_size, + upb_value_constptr(f), ctx->arena); + if (!ok) _upb_DefBuilder_OomErr(ctx); } - const size_t json_size = strlen(json_name); - ok = upb_strtable_insert(&m->jtof, json_name, json_size, - upb_value_constptr(f), ctx->arena); - if (!ok) _upb_DefBuilder_OomErr(ctx); - if (upb_inttable_lookup(&m->itof, field_number, NULL)) { _upb_DefBuilder_Errf(ctx, "duplicate field number (%u)", field_number); }