Skip to content

Commit 9806994

Browse files
Add JSON conformance test that a single value provided for a repeated field should parse fail.
This adds tests for both an object instead of an array for a repeated submessage field, and a number instead of an array for a repeated int32 field. C++Proto fails both tests. Pure-PHP fails this test only for the numbers case. PiperOrigin-RevId: 791266294
1 parent 67f4347 commit 9806994

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

‎conformance/binary_json_conformance_suite.cc‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,8 +1981,6 @@ void BinaryAndJsonConformanceSuiteImpl<MessageType>::RunJsonTests() {
19811981
"{\"optionalString\":\"Hello, World!\"}",
19821982
"optional_string: 'Hello, World!'");
19831983

1984-
// NOTE: The spec for JSON support is still being sorted out, these may not
1985-
// all be correct.
19861984
RunJsonTestsForFieldNameConvention();
19871985
RunJsonTestsForNonRepeatedTypes();
19881986
RunJsonTestsForRepeatedTypes();
@@ -2902,6 +2900,14 @@ void BinaryAndJsonConformanceSuiteImpl<
29022900
ExpectParseFailureForJson(
29032901
"RepeatedFieldWrongElementTypeExpectingMessagesGotString", REQUIRED,
29042902
R"({"repeatedNestedMessage": [{"a": 1}, "2"]})");
2903+
2904+
// A singular field where a repeated field was expected is not allowed, even
2905+
// if it is the right type.
2906+
ExpectParseFailureForJson("SingleValueForRepeatedFieldInt32", REQUIRED,
2907+
R"({"repeatedInt32": 1})");
2908+
ExpectParseFailureForJson("SingleValueForRepeatedFieldMessage", REQUIRED,
2909+
R"({"repeatedNestedMessage": {"a": 1}})");
2910+
29052911
// Trailing comma in the repeated field is not allowed.
29062912
ExpectParseFailureForJson("RepeatedFieldTrailingComma", RECOMMENDED,
29072913
R"({"repeatedInt32": [1, 2, 3, 4,]})");

‎conformance/failure_list_cpp.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ Recommended.*.FieldMaskTooManyUnderscore.JsonOutput
3535
Recommended.*.JsonInput.FieldMaskInvalidCharacter # Should have failed to parse, but didn't.
3636
Required.*.TimestampProtoNanoTooLarge.JsonOutput # Should have failed to serialize, but didn't.
3737
Required.*.TimestampProtoNegativeNanos.JsonOutput # Should have failed to serialize, but didn't.
38+
Required.*.JsonInput.SingleValueForRepeatedFieldInt32 # Should have failed to parse, but didn't.
39+
Required.*.JsonInput.SingleValueForRepeatedFieldMessage # Should have failed to parse, but didn't.

‎conformance/failure_list_php.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ Required.*.DurationProtoNanosWrongSign.JsonOutput # Should have failed to serial
4444
Required.*.DurationProtoNanosWrongSignNegativeSecs.JsonOutput # Should have failed to serialize, but didn't.
4545
Required.*.TimestampProtoNanoTooLarge.JsonOutput # Should have failed to serialize, but didn't.
4646
Required.*.TimestampProtoNegativeNanos.JsonOutput # Should have failed to serialize, but didn't.
47+
Required.*.JsonInput.SingleValueForRepeatedFieldInt32 # Should have failed to parse, but didn't.

0 commit comments

Comments
 (0)