diff --git a/conformance/binary_json_conformance_suite.cc b/conformance/binary_json_conformance_suite.cc index 45d9c1678d..90d914c647 100644 --- a/conformance/binary_json_conformance_suite.cc +++ b/conformance/binary_json_conformance_suite.cc @@ -2125,6 +2125,24 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() { } } )"); + RunValidJsonTest( + "StructWithEmptyListValue", REQUIRED, + R"({ + "optionalStruct": { + "listValue": [] + } + })", + R"( + optional_struct: { + fields: { + key: "listValue" + value: { + list_value: { + } + } + } + } + )"); // Value RunValidJsonTest( "ValueAcceptInteger", REQUIRED, diff --git a/conformance/failure_list_ruby.txt b/conformance/failure_list_ruby.txt index 651cb55f57..f9e1c2241a 100644 --- a/conformance/failure_list_ruby.txt +++ b/conformance/failure_list_ruby.txt @@ -26,6 +26,7 @@ Required.Proto3.JsonInput.DoubleFieldMinPositiveValue.ProtobufOutput Required.Proto3.JsonInput.DoubleFieldNan.JsonOutput Required.Proto3.JsonInput.DurationMinValue.JsonOutput Required.Proto3.JsonInput.DurationRepeatedValue.JsonOutput +Required.Proto3.JsonInput.EmptyFieldMask.JsonOutput Required.Proto3.JsonInput.FloatFieldInfinity.JsonOutput Required.Proto3.JsonInput.FloatFieldNan.JsonOutput Required.Proto3.JsonInput.FloatFieldNegativeInfinity.JsonOutput diff --git a/conformance/failure_list_ruby_mac.txt b/conformance/failure_list_ruby_mac.txt index 89270326c4..86a5da183d 100644 --- a/conformance/failure_list_ruby_mac.txt +++ b/conformance/failure_list_ruby_mac.txt @@ -18,26 +18,6 @@ Recommended.Proto3.JsonInput.TimestampHas6FractionalDigits.Validator Recommended.Proto3.JsonInput.Uint64FieldBeString.Validator Required.DurationProtoInputTooLarge.JsonOutput Required.DurationProtoInputTooSmall.JsonOutput -Required.Proto3.JsonInput.Any.JsonOutput -Required.Proto3.JsonInput.Any.ProtobufOutput -Required.Proto3.JsonInput.AnyNested.JsonOutput -Required.Proto3.JsonInput.AnyNested.ProtobufOutput -Required.Proto3.JsonInput.AnyUnorderedTypeTag.JsonOutput -Required.Proto3.JsonInput.AnyUnorderedTypeTag.ProtobufOutput -Required.Proto3.JsonInput.AnyWithDuration.JsonOutput -Required.Proto3.JsonInput.AnyWithDuration.ProtobufOutput -Required.Proto3.JsonInput.AnyWithFieldMask.JsonOutput -Required.Proto3.JsonInput.AnyWithFieldMask.ProtobufOutput -Required.Proto3.JsonInput.AnyWithInt32ValueWrapper.JsonOutput -Required.Proto3.JsonInput.AnyWithInt32ValueWrapper.ProtobufOutput -Required.Proto3.JsonInput.AnyWithStruct.JsonOutput -Required.Proto3.JsonInput.AnyWithStruct.ProtobufOutput -Required.Proto3.JsonInput.AnyWithTimestamp.JsonOutput -Required.Proto3.JsonInput.AnyWithTimestamp.ProtobufOutput -Required.Proto3.JsonInput.AnyWithValueForInteger.JsonOutput -Required.Proto3.JsonInput.AnyWithValueForInteger.ProtobufOutput -Required.Proto3.JsonInput.AnyWithValueForJsonObject.JsonOutput -Required.Proto3.JsonInput.AnyWithValueForJsonObject.ProtobufOutput Required.Proto3.JsonInput.DoubleFieldMaxNegativeValue.JsonOutput Required.Proto3.JsonInput.DoubleFieldMaxNegativeValue.ProtobufOutput Required.Proto3.JsonInput.DoubleFieldMinPositiveValue.JsonOutput @@ -45,8 +25,6 @@ Required.Proto3.JsonInput.DoubleFieldMinPositiveValue.ProtobufOutput Required.Proto3.JsonInput.DoubleFieldNan.JsonOutput Required.Proto3.JsonInput.DurationMinValue.JsonOutput Required.Proto3.JsonInput.DurationRepeatedValue.JsonOutput -Required.Proto3.JsonInput.FieldMask.JsonOutput -Required.Proto3.JsonInput.FieldMask.ProtobufOutput Required.Proto3.JsonInput.FloatFieldInfinity.JsonOutput Required.Proto3.JsonInput.FloatFieldNan.JsonOutput Required.Proto3.JsonInput.FloatFieldNegativeInfinity.JsonOutput @@ -91,3 +69,5 @@ Required.Proto3.JsonInput.IgnoreUnknownJsonNumber.ProtobufOutput Required.Proto3.JsonInput.IgnoreUnknownJsonObject.ProtobufOutput Required.Proto3.JsonInput.IgnoreUnknownJsonString.ProtobufOutput Required.Proto3.JsonInput.IgnoreUnknownJsonTrue.ProtobufOutput +Recommended.Proto3.JsonInput.FieldMaskInvalidCharacter +Required.Proto3.JsonInput.EmptyFieldMask.JsonOutput diff --git a/ruby/ext/google/protobuf_c/encode_decode.c b/ruby/ext/google/protobuf_c/encode_decode.c index 5ead9b8984..4b79368552 100644 --- a/ruby/ext/google/protobuf_c/encode_decode.c +++ b/ruby/ext/google/protobuf_c/encode_decode.c @@ -1237,6 +1237,34 @@ static void putjsonany(VALUE msg_rb, const Descriptor* desc, upb_sink_endmsg(sink, &status); } +static void putjsonlistvalue( + VALUE msg_rb, const Descriptor* desc, + upb_sink* sink, int depth, bool emit_defaults) { + upb_status status; + upb_sink subsink; + MessageHeader* msg = NULL; + const upb_fielddef* f = upb_msgdef_itof(desc->msgdef, 1); + uint32_t offset = + desc->layout->fields[upb_fielddef_index(f)].offset + + sizeof(MessageHeader); + VALUE ary; + + TypedData_Get_Struct(msg_rb, MessageHeader, &Message_type, msg); + + upb_sink_startmsg(sink); + + ary = DEREF(msg, offset, VALUE); + + if (ary == Qnil || RepeatedField_size(ary) == 0) { + upb_sink_startseq(sink, getsel(f, UPB_HANDLER_STARTSEQ), &subsink); + upb_sink_endseq(sink, getsel(f, UPB_HANDLER_ENDSEQ)); + } else { + putary(ary, f, sink, depth, emit_defaults, true); + } + + upb_sink_endmsg(sink, &status); +} + static void putmsg(VALUE msg_rb, const Descriptor* desc, upb_sink *sink, int depth, bool emit_defaults, bool is_json, bool open_msg) { @@ -1244,11 +1272,18 @@ static void putmsg(VALUE msg_rb, const Descriptor* desc, upb_msg_field_iter i; upb_status status; - if (is_json && upb_msgdef_wellknowntype(desc->msgdef) == UPB_WELLKNOWN_ANY) { + if (is_json && + upb_msgdef_wellknowntype(desc->msgdef) == UPB_WELLKNOWN_ANY) { putjsonany(msg_rb, desc, sink, depth, emit_defaults); return; } + if (is_json && + upb_msgdef_wellknowntype(desc->msgdef) == UPB_WELLKNOWN_LISTVALUE) { + putjsonlistvalue(msg_rb, desc, sink, depth, emit_defaults); + return; + } + if (open_msg) { upb_sink_startmsg(sink); } diff --git a/ruby/travis-test.sh b/ruby/travis-test.sh index 76d424b0af..7c89e54686 100755 --- a/ruby/travis-test.sh +++ b/ruby/travis-test.sh @@ -15,7 +15,6 @@ test_version() { # TODO(teboring): timestamp parsing is incorrect only on mac due to mktime. RUBY_CONFORMANCE=test_ruby_mac fi - return 0 if [ "$version" == "jruby-1.7" ] ; then # No conformance tests yet -- JRuby is too broken to run them.