Commit graph

38 commits

Author SHA1 Message Date
Protobuf Team Bot
0e436a47e8 Update conformance tests with updated relaxed duplicate key handling in ProtoJSON
The spec has been relaxed such that the preferred behavior is last-wins, and parse-failure if last-wins is not implementable. The conformance test is updated correspondingly to pass under either of those permissible behaviors.

https://github.com/protocolbuffers/protobuf/issues/28791

PiperOrigin-RevId: 957979215
2026-08-02 09:58:52 -07:00
Protobuf Team Bot
f8dfd63322 Add conformance tests for Timestamp parsing
In general, runtimes also expose Timestamp parsing by utils but it is conformance-testable via JSON.

Timestamp format is RFC3339 which looks like `1970-01-01T00:00:00Z` (for UTC timestamps) or `1970-01-02T01:00:00+02:00` (with timezone).

There's actually two different reasons why a Timestamp format might be invalid.

RFC3339 spec has some bright line rules as follows:

- All of the segments must be the expected fixed width (eg: month is always 2 digits, 1970-01-01 and not 1970-1-1).
- Year must be [0001 .. 9999]
- Month must be [01 .. 12]
- Day must be valid for the relevant month, including that Feb 29 is only legal in leap years.
- The literal `T` comes next (spec ambiguous if `t` is also allowed, not tested in this change)
- Hour must be [00..23]
- Minute must be [00..59]
- Second must be [00..59]
- Subseconds are unconstrained precision
- Timezone must be Z for UTC or else formatted with HH:MM where HH is [00..23] and MM is [00..59].

Protobuf has a few extra effective constraints compared to RFC3339 though, which are _mostly_ academic:

- We disallow subsecond resolution has more than 9 decimal digits
- Some RFC3339 timestamps which are not-UTC-timezone in year 1 or year 9999 are not valid in Protobuf [*reason explained below]

Note that GoProto uses a std RFC3339 parser and does implement these bonus restrictions rules on top.

* The reason is that `0001-01-01T00:00:00+00:01` is a legal RFC3339 timestamp, but is BCE in UTC timezone. This is an oddity: we otherwise say parsers should accept RFC3339 timestamps with any timezone, but must serialize as UTC. This timestamp is not legally representable in RFC3339 in UTC, and the google.protobuf.Timestamp field secs is documented that `-62135596800` is the minimum legal value, but this timestamp is earlier than that. Because this situation only occurs at the years 1 and 9999 its not plausibly a concern on real user data, its only an oddity that you must either reject this legal RFC3339 timestamp at parse time, or else accept it but produce an in-memory google.protobuf.Timestamp which is officially 'invalid' and cannot be printed back out.

PiperOrigin-RevId: 954603113
2026-07-27 06:54:18 -07:00
Tony Liao
cb440834fd Document Python & PHP non-conformance where booleans are accepted by int and float fields.
PiperOrigin-RevId: 952905948
2026-07-23 12:51:55 -07:00
Protobuf Team Bot
e8923a8ea7 Add conformance tests for utf8 validation.
PiperOrigin-RevId: 858895922
2026-01-20 21:30:50 -08:00
Protobuf Team Bot
448b53feed Add conformance tests for overlong varints as tags.
No wire format should ever contain an overlong varint, so the topic here is only how to react to non-standard and potentially corrupted data.

The situation today is that there's 4 main ways that implementations deal when parsing tags:

1) parse up to 10 bytes, cast to uint32
2) parse up to 10 bytes, reject if it is above uint32_max
3) parse up to 5 bytes, cast to uint32
4) parse up to 5 bytes, reject if it is above uint32_max

Of our primary supported implementations, these four strategies are used by Java, Go, C++ and upb correspondingly.

Based on examining the situation, the decision taken is that:

- Coercing down silently ignoring bits in the tag is dangerous to interpretation-confusion / silent misparsing, which means Java approach is dangerous.

- Needing to support parsing up to 10 bytes (even when they may just be all 0x80 and no content) would have real performance implications on the upb and C++ parsers. Since it should really never happen taking any performance hit on all parses based on a hypothetical is considered undesirable.

For that reason, the conformance test is set to match upb's behavior, which is slight mismatch to C++ and Go behavior today (in different ways), and larger mismatch to the Java behavior today.

Because fixing this 'bug' may be disruptive to a customer in theory (though it would probably mean they have some bad data that was accidentally parsing), we may hold back fixing the behavior to a breaking change release; this change to the conformance suite only establishes the decision on preferred behavior.

PiperOrigin-RevId: 841856475
2025-12-08 11:55:52 -08:00
Dan Hudlow
bbe7691e6f Fix expected parse failures that may fail for the wrong reasons (#21873)
These expected JSON parse failures will currently fail for reasons _other_ than the tested behavior.

Note that I'm being a little cute here by fixing the tests that [now apparently contradict the spec](c18c8a72de (diff-98c94e5ab37db71fd002eff0d9cb2cfae9b0058ea00b412b466312ad819029d7)). I happen to think the spec is misguided and these tests are better behavior, but I _expect_ the tests will end up being updated to match the spec.

Closes #21873

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/21873 from hudlow:misleading-parse-failures edeb1298ba
PiperOrigin-RevId: 773893058
2025-06-20 17:06:31 -07:00
Mike Kruskal
f2ec951597 Fix python JSON parser to accept string fields containing integer-equivalent floats.
This fixes non-conformant behavior in python.

PiperOrigin-RevId: 704529468
2024-12-09 20:53:41 -08:00
Mike Kruskal
482752a78a Make Python/C++ reject unmatched end-group tag.
This brings it into conformance with our spec and other languages.

PiperOrigin-RevId: 702914786
2024-12-04 17:23:06 -08:00
Mike Kruskal
fc048f4fe3 Add a conformance test for invalid end group tag.
Java and Python/C++ are both non-conformant, since they allow these invalid payloads.

PiperOrigin-RevId: 694312115
2024-11-07 18:13:30 -08:00
Sandy Zhang
cb304bde36 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
2024-11-07 15:36:49 -08:00
Anton Grbin
86abf35ef5 Python JSON parser: Ignore invalid enum string values if ignore_unknown_fields is set (#15887)
# Motivation

This PR fixes failing conformance tests for python with name `IgnoreUnknownEnumStringValue`.

The JSON parsing spec was discussed in https://github.com/protocolbuffers/protobuf/issues/7392.

Recent equivalent changes for other languages:
* Swift: https://github.com/apple/swift-protobuf/pull/1345
* C#: https://github.com/protocolbuffers/protobuf/pull/15758

# Changes

- 1st commit is a noop  refactoring to make relevant _ConvertScalarFieldValue invocations localized
- 2nd commit introduces the child exception of `ParseError` named `EnumStringValueParseError` which is suppressed if `ignore_unknown_fields` is set
- 3rd commit updates the conformance test failure lists

Closes #15887

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/15887 from noom:anton/7392/fix-python-test fbcc93a232
PiperOrigin-RevId: 619288323
2024-03-26 13:22:12 -07:00
Anton Grbin
0fa67a94aa JSON conformance test: repeated with a mix of known and unknown enum string values (#15885)
This test was suggested by @jskeet in the related issue: https://github.com/protocolbuffers/protobuf/issues/7392#issuecomment-1884666885

I am not confident that the failure lists are comprehensive (I only run a few tests locally) -- will fix once we get CI results.

Closes #15885

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/15885 from noom:anton/7392/conformance-repeated-enum 60c35f0339
PiperOrigin-RevId: 609487784
2024-02-22 13:59:08 -08:00
Protobuf Team Bot
42ecd61b3e Extend Proto2 JSON test cases to cover more of the preexisting Proto3 JSON cases.
PiperOrigin-RevId: 595998208
2024-01-05 08:13:18 -08:00
Mike Kruskal
15eccf3ec4 Implement Editions in Pure Python.
This change only covers pure python, and follow-up changes will handle C++/upb variants and actually enable editions support.  The C++ one works (as evident from the conformance tests), but needs some APIs added to allow for testing.

PiperOrigin-RevId: 580304039
2023-11-07 14:40:26 -08:00
Sandy Zhang
81068e8e8c Internal change
PiperOrigin-RevId: 566426899
2023-09-18 15:17:56 -07:00
Anton Grbin
09f4901084 Copybara import of the project:
--
064b263c42 by Anton Grbin <anton@noom.com>:

squash and rebase

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/9534 from noom:anton/MIN-2347/json_conformance_unknown_fields 064b263c42
PiperOrigin-RevId: 488667851
2022-11-15 08:44:05 -08:00
Joshua Haberman
f77065d4eb Sync from Piper @316511779
PROTOBUF_SYNC_PIPER
2020-06-15 11:48:47 -07:00
Joshua Haberman
183cdec7cd Sync from Piper @314226556
PROTOBUF_SYNC_PIPER
2020-06-01 16:32:31 -07:00
Yilun Chong
d8c2501b43 down integration from internal 2019-02-22 18:13:33 +08:00
Paul Yang
7f42d6d0bc
Fix empty FieldMask json encoding/decoding (#5605)
* Fix empty FieldMask json encoding/decoding

* Add failed test to python's conformance failure list
2019-01-22 15:35:12 -08:00
Yilun Chong
0adb74c2d3 Down-integrate internal changes to github. (#5555)
* Down-integrate internal changes to github.

* fix python conformance test

* fix csharp conformance test

* add back java map_lite_test.proto's optimize for option

* fix php conformance test
2019-01-08 15:06:30 -08:00
Feng Xiao
6bbe197e9c Down-integrate from google3. 2018-08-08 17:00:41 -07:00
Paul Yang
26eeec93e4
Enable ignoring unknown in json parsing in php (#4839)
* Enable ignoring unknown in json parsing in php

* Update generated descriptor files

* Update failure list for other languages.

* Remove unnecessary php files
2018-07-09 14:29:23 -07:00
Jisi Liu
1a7a7fca80 Merge from google internal 2017-10-18 12:22:18 -07:00
Jisi Liu
19b8c8bfd3 Update conformance tests again. 2017-07-25 16:08:17 -07:00
Jisi Liu
de6debcf2b Fix conformance tests 2017-07-25 14:37:37 -07:00
Jisi Liu
759245a49a Merge from master 2017-07-25 11:52:33 -07:00
Jisi Liu
7986ca7e53 Update conformance tests 2017-07-19 12:07:35 -07:00
Jisi Liu
09354db143 Merge from Google internal for 3.4 release 2017-07-18 15:38:30 -07:00
Adam Cozzette
5a76e633ea Integrated internal changes from Google 2016-11-17 16:59:59 -08:00
Bo Yang
23d4688cce Fix python bugs for internal integration. 2016-10-10 11:43:48 -07:00
Bo Yang
cc8ca5b6a5 Integrate internal changes 2016-10-10 11:23:36 -07:00
Thomas Van Lenten
80f65d2df8 Add note about JSON tests maybe being wrong. (#1992)
Add note about JSON tests maybe being wrong.

- Add note about the JSON test maybe not being correct yet.
- Add test to checks the generated names for double underscores to be sure they
  are what is expected.
2016-08-23 08:19:45 -04:00
Thomas Van Lenten
ac3df39c22 Add conformance test for zero fields in oneofs. (#1939)
* Add conformance test for zero fields in oneofs.
* Add failures to the "expected" files.
2016-08-11 09:44:07 -04:00
Josh Haberman
bd98eae1c9 Fixed Python by updating failure lists and fixed a few broken tests.
Python 2.x doesn't detect unpaired surrogates so we have to
do that manually.
2016-06-03 09:39:38 -07:00
Josh Haberman
06fd6fa850 Fixed Python 3.x C++ build, and updated conformance failure lists. 2016-01-15 17:26:44 -08:00
Josh Haberman
e891c29f9b Allow conformance test runner to tolerate crashes, and re-enable conformance tests. 2016-01-11 16:15:46 -08:00
Josh Haberman
4b31ffa488 Added Python failure lists, and fixes to make sure failure propagates. 2015-12-03 12:54:54 -08:00