Add JSON parse conformance tests for non-numeric string in numeric fields.

Adds test coverage for invalid empty strings (e.g. ""), non-numeric strings (e.g. "abc"), and partially-numeric strings (e.g. "12abc"), as well as valid exponential numeric strings ("1e5)

We will target enforcing non-conformant cases that should have failed to parse but didn't in upb in v30.x (our ~annual breaking release in some languages). Conformance failures to accept input we previously failed on can be landed at any time.

PiperOrigin-RevId: 694269337
pull/19081/head
Sandy Zhang 2 months ago committed by Copybara-Service
parent dceaac9980
commit cb304bde36
  1. 28
      conformance/binary_json_conformance_suite.cc
  2. 2
      conformance/conformance_test.cc
  3. 1
      conformance/failure_list_cpp.txt
  4. 35
      conformance/failure_list_jruby_ffi.txt
  5. 1
      conformance/failure_list_php.txt
  6. 35
      conformance/failure_list_php_c.txt
  7. 1
      conformance/failure_list_python.txt
  8. 2
      conformance/failure_list_python_cpp.txt
  9. 1
      conformance/failure_list_python_upb.txt
  10. 35
      conformance/failure_list_ruby.txt
  11. 35
      upb/conformance/conformance_upb_failures.txt

@ -2289,6 +2289,10 @@ void BinaryAndJsonConformanceSuiteImpl<
RunValidJsonTest("Int32FieldStringValueEscaped", REQUIRED,
R"({"optionalInt32": "2\u003147483647"})",
"optional_int32: 2147483647");
RunValidJsonTest("Int32FieldStringValueZero", REQUIRED,
R"({"optionalInt32": "0"})", "optional_int32: 0");
RunValidJsonTest("Int32FieldQuotedExponentialValue", REQUIRED,
R"({"optionalInt32": "1e5"})", "optional_int32: 100000");
// Parsers reject out-of-bound integer values.
ExpectParseFailureForJson("Int32FieldTooLarge", REQUIRED,
@ -2314,6 +2318,12 @@ void BinaryAndJsonConformanceSuiteImpl<
ExpectParseFailureForJson("Uint64FieldNotInteger", REQUIRED,
R"({"optionalUint64": "0.5"})");
// Parser reject non-numeric string values.
ExpectParseFailureForJson("Int32FieldStringValuePartiallyNumeric", REQUIRED,
R"({"optionalInt32": "12abc"})");
ExpectParseFailureForJson("Int32FieldStringValueNonNumeric", REQUIRED,
R"({"optionalInt32": "abc"})");
// Parser reject empty string values.
ExpectParseFailureForJson("Int32FieldEmptyString", REQUIRED,
R"({"optionalInt32": ""})");
@ -2418,6 +2428,9 @@ void BinaryAndJsonConformanceSuiteImpl<
// Values can be quoted.
RunValidJsonTest("FloatFieldQuotedValue", REQUIRED,
R"({"optionalFloat": "1"})", "optional_float: 1");
RunValidJsonTest("FloatFieldQuotedExponentialValue", REQUIRED,
R"({"optionalFloat": "1.175494e-38"})",
"optional_float: 1.175494e-38");
// Special values.
RunValidJsonTest("FloatFieldNan", REQUIRED, R"({"optionalFloat": "NaN"})",
"optional_float: nan");
@ -2458,6 +2471,12 @@ void BinaryAndJsonConformanceSuiteImpl<
ExpectParseFailureForJson("FloatFieldEmptyString", REQUIRED,
R"({"optionalFloat": ""})");
// Parser reject non-numeric string values.
ExpectParseFailureForJson("FloatFieldStringValuePartiallyNumeric", REQUIRED,
R"({"optionalFloat": "12abc"})");
ExpectParseFailureForJson("FloatFieldStringValueNonNumeric", REQUIRED,
R"({"optionalFloat": "abc"})");
// Double fields.
RunValidJsonTest("DoubleFieldMinPositiveValue", REQUIRED,
R"({"optionalDouble": 2.22507e-308})",
@ -2474,6 +2493,9 @@ void BinaryAndJsonConformanceSuiteImpl<
// Values can be quoted.
RunValidJsonTest("DoubleFieldQuotedValue", REQUIRED,
R"({"optionalDouble": "1"})", "optional_double: 1");
RunValidJsonTest("DoubleFieldQuotedExponentialValue", REQUIRED,
R"({"optionalDouble": "2.22507e-308"})",
"optional_double: 2.22507e-308");
// Special values.
RunValidJsonTest("DoubleFieldNan", REQUIRED, R"({"optionalDouble": "NaN"})",
"optional_double: nan");
@ -2514,6 +2536,12 @@ void BinaryAndJsonConformanceSuiteImpl<
ExpectParseFailureForJson("DoubleFieldEmptyString", REQUIRED,
R"({"optionalDouble": ""})");
// Parser reject non-numeric string values.
ExpectParseFailureForJson("DoubleFieldStringValuePartiallyNumeric", REQUIRED,
R"({"optionalDouble": "12abc"})");
ExpectParseFailureForJson("DoubleFieldStringValueNonNumeric", REQUIRED,
R"({"optionalDouble": "abc"})");
// Enum fields.
RunValidJsonTest("EnumField", REQUIRED, R"({"optionalNestedEnum": "FOO"})",
"optional_nested_enum: FOO");

@ -182,7 +182,7 @@ bool CheckSetEmpty(const absl::btree_map<std::string, TestStatus>& set_to_check,
namespace google {
namespace protobuf {
constexpr int kMaximumWildcardExpansions = 5;
constexpr int kMaximumWildcardExpansions = 10;
ConformanceTestSuite::ConformanceRequestSetting::ConformanceRequestSetting(
ConformanceLevel level, conformance::WireFormat input_format,

@ -35,3 +35,4 @@ Recommended.*.FieldMaskNumbersDontRoundTrip.JsonOutput
Recommended.*.FieldMaskPathsDontRoundTrip.JsonOutput # Should have failed to serialize, but didn't.
Recommended.*.FieldMaskTooManyUnderscore.JsonOutput # Should have failed to serialize, but didn't.
Recommended.*.JsonInput.FieldMaskInvalidCharacter # Should have failed to parse, but didn't.
Required.*.JsonInput.Int32FieldQuotedExponentialValue.* # Failed to parse input or produce output.

@ -1,24 +1,11 @@
Required.Editions_Proto2.JsonInput.DoubleFieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto2.JsonInput.FloatFieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto2.JsonInput.Int32FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto2.JsonInput.Int64FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto2.JsonInput.Uint32FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto2.JsonInput.Uint64FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto3.JsonInput.DoubleFieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto3.JsonInput.FloatFieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto3.JsonInput.Int32FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto3.JsonInput.Int64FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto3.JsonInput.Uint32FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto3.JsonInput.Uint64FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto2.JsonInput.DoubleFieldEmptyString # Should have failed to parse, but didn't.
Required.Proto2.JsonInput.FloatFieldEmptyString # Should have failed to parse, but didn't.
Required.Proto2.JsonInput.Int32FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto2.JsonInput.Int64FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto2.JsonInput.Uint32FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto2.JsonInput.Uint64FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto3.JsonInput.DoubleFieldEmptyString # Should have failed to parse, but didn't.
Required.Proto3.JsonInput.FloatFieldEmptyString # Should have failed to parse, but didn't.
Required.Proto3.JsonInput.Int32FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto3.JsonInput.Int64FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto3.JsonInput.Uint32FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto3.JsonInput.Uint64FieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.DoubleFieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.FloatFieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.Int32FieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.Int64FieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.Uint32FieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.Uint64FieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.DoubleFieldStringValueNonNumeric # Should have failed to parse, but didn't.
Required.*.JsonInput.DoubleFieldStringValuePartiallyNumeric # Should have failed to parse, but didn't.
Required.*.JsonInput.FloatFieldStringValueNonNumeric # Should have failed to parse, but didn't.
Required.*.JsonInput.FloatFieldStringValuePartiallyNumeric # Should have failed to parse, but didn't.
Required.*.JsonInput.Int32FieldQuotedExponentialValue.* # Failed to parse input or produce output.

@ -34,3 +34,4 @@ Required.*.ProtobufInput.ValidDataOneof.MESSAGE.Merge.ProtobufOutput
Required.*.ProtobufInput.ValidDataRepeated.FLOAT.PackedInput.JsonOutput
Required.*.ProtobufInput.ValidDataRepeated.FLOAT.UnpackedInput.JsonOutput
Required.*.ProtobufInput.ValidDataScalar.FLOAT[2].JsonOutput
Required.*.JsonInput.Int32FieldQuotedExponentialValue.* # Failed to parse input or produce output.

@ -1,28 +1,15 @@
Recommended.Proto2.JsonInput.FieldNameExtension.Validator
Required.Editions_Proto2.JsonInput.DoubleFieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto2.JsonInput.FloatFieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto2.JsonInput.Int32FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto2.JsonInput.Int64FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto2.JsonInput.Uint32FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto2.JsonInput.Uint64FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto3.JsonInput.DoubleFieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto3.JsonInput.FloatFieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto3.JsonInput.Int32FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto3.JsonInput.Int64FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto3.JsonInput.Uint32FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto3.JsonInput.Uint64FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto2.JsonInput.DoubleFieldEmptyString # Should have failed to parse, but didn't.
Required.Proto2.JsonInput.FloatFieldEmptyString # Should have failed to parse, but didn't.
Required.Proto2.JsonInput.Int32FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto2.JsonInput.Int64FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto2.JsonInput.Uint32FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto2.JsonInput.Uint64FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto3.JsonInput.DoubleFieldEmptyString # Should have failed to parse, but didn't.
Required.Proto3.JsonInput.FloatFieldEmptyString # Should have failed to parse, but didn't.
Required.Proto3.JsonInput.Int32FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto3.JsonInput.Int64FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto3.JsonInput.Uint32FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto3.JsonInput.Uint64FieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.DoubleFieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.FloatFieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.Int32FieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.Int64FieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.Uint32FieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.Uint64FieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.DoubleFieldStringValueNonNumeric # Should have failed to parse, but didn't.
Required.*.JsonInput.DoubleFieldStringValuePartiallyNumeric # Should have failed to parse, but didn't.
Required.*.JsonInput.FloatFieldStringValueNonNumeric # Should have failed to parse, but didn't.
Required.*.JsonInput.FloatFieldStringValuePartiallyNumeric # Should have failed to parse, but didn't.
Required.*.JsonInput.Int32FieldQuotedExponentialValue.* # Failed to parse input or produce output.
Required.Proto2.JsonInput.BoolFieldFalse.JsonOutput
Required.Proto2.JsonInput.BoolFieldFalse.ProtobufOutput
Required.Proto2.JsonInput.EnumField.JsonOutput

@ -0,0 +1 @@
Required.*.JsonInput.Int32FieldQuotedExponentialValue.* # Failed to parse input or produce output.

@ -6,3 +6,5 @@
#
# TODO: insert links to corresponding bugs tracking the issue.
# Should we use GitHub issues or the Google-internal bug tracker?
Required.*.JsonInput.Int32FieldQuotedExponentialValue.* # Failed to parse input or produce output.

@ -0,0 +1 @@
Required.*.JsonInput.Int32FieldQuotedExponentialValue.* # Failed to parse input or produce output.

@ -1,24 +1,11 @@
Required.Editions_Proto2.JsonInput.DoubleFieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto2.JsonInput.FloatFieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto2.JsonInput.Int32FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto2.JsonInput.Int64FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto2.JsonInput.Uint32FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto2.JsonInput.Uint64FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto3.JsonInput.DoubleFieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto3.JsonInput.FloatFieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto3.JsonInput.Int32FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto3.JsonInput.Int64FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto3.JsonInput.Uint32FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto3.JsonInput.Uint64FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto2.JsonInput.DoubleFieldEmptyString # Should have failed to parse, but didn't.
Required.Proto2.JsonInput.FloatFieldEmptyString # Should have failed to parse, but didn't.
Required.Proto2.JsonInput.Int32FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto2.JsonInput.Int64FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto2.JsonInput.Uint32FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto2.JsonInput.Uint64FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto3.JsonInput.DoubleFieldEmptyString # Should have failed to parse, but didn't.
Required.Proto3.JsonInput.FloatFieldEmptyString # Should have failed to parse, but didn't.
Required.Proto3.JsonInput.Int32FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto3.JsonInput.Int64FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto3.JsonInput.Uint32FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto3.JsonInput.Uint64FieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.DoubleFieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.FloatFieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.Int32FieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.Int64FieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.Uint32FieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.Uint64FieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.DoubleFieldStringValueNonNumeric # Should have failed to parse, but didn't.
Required.*.JsonInput.DoubleFieldStringValuePartiallyNumeric # Should have failed to parse, but didn't.
Required.*.JsonInput.FloatFieldStringValueNonNumeric # Should have failed to parse, but didn't.
Required.*.JsonInput.FloatFieldStringValuePartiallyNumeric # Should have failed to parse, but didn't.
Required.*.JsonInput.Int32FieldQuotedExponentialValue.* # Failed to parse input or produce output.

@ -1,24 +1,11 @@
Required.Editions_Proto2.JsonInput.DoubleFieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto2.JsonInput.FloatFieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto2.JsonInput.Int32FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto2.JsonInput.Int64FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto2.JsonInput.Uint32FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto2.JsonInput.Uint64FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto3.JsonInput.DoubleFieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto3.JsonInput.FloatFieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto3.JsonInput.Int32FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto3.JsonInput.Int64FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto3.JsonInput.Uint32FieldEmptyString # Should have failed to parse, but didn't.
Required.Editions_Proto3.JsonInput.Uint64FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto2.JsonInput.DoubleFieldEmptyString # Should have failed to parse, but didn't.
Required.Proto2.JsonInput.FloatFieldEmptyString # Should have failed to parse, but didn't.
Required.Proto2.JsonInput.Int32FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto2.JsonInput.Int64FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto2.JsonInput.Uint32FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto2.JsonInput.Uint64FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto3.JsonInput.DoubleFieldEmptyString # Should have failed to parse, but didn't.
Required.Proto3.JsonInput.FloatFieldEmptyString # Should have failed to parse, but didn't.
Required.Proto3.JsonInput.Int32FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto3.JsonInput.Int64FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto3.JsonInput.Uint32FieldEmptyString # Should have failed to parse, but didn't.
Required.Proto3.JsonInput.Uint64FieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.DoubleFieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.FloatFieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.Int32FieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.Int64FieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.Uint32FieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.Uint64FieldEmptyString # Should have failed to parse, but didn't.
Required.*.JsonInput.DoubleFieldStringValueNonNumeric # Should have failed to parse, but didn't.
Required.*.JsonInput.DoubleFieldStringValuePartiallyNumeric # Should have failed to parse, but didn't.
Required.*.JsonInput.FloatFieldStringValueNonNumeric # Should have failed to parse, but didn't.
Required.*.JsonInput.FloatFieldStringValuePartiallyNumeric # Should have failed to parse, but didn't.
Required.*.JsonInput.Int32FieldQuotedExponentialValue.* # Failed to parse input or produce output.

Loading…
Cancel
Save