Skip to content

fix: accept repeated NullValue elements in ProtoJSON - #2373

Merged
alexander-fenster merged 1 commit into
protobufjs:masterfrom
Ram-blip:fix-protojson-repeated-nullvalue
Jul 7, 2026
Merged

alexander-fenster merged 1 commit into
protobufjs:masterfrom
Ram-blip:fix-protojson-repeated-nullvalue

Conversation

@Ram-blip

@Ram-blip Ram-blip commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

ProtoJSON currently rejects null elements in repeated google.protobuf.NullValue fields before enum conversion runs.

Repeated null elements are generally rejected, but google.protobuf.NullValue is the documented exception because its JSON representation is null. This change allows repeated google.protobuf.NullValue elements to reach the existing readEnum handling, which already converts null to NULL_VALUE.

Behavior

Before this change:

protojson.fromJson(NullMsg, {
  nullValues: [null, null]
});

throws:

.test.NullMsg.nullValues: null element: null

After this change, the same input parses as:

{
  nullValues: [0, 0]
}

and serializes back to:

{
  nullValues: [null, null]
}

Ordinary repeated null elements remain rejected.

Tests

Added regression coverage in tests/api_protojson.js for repeated google.protobuf.NullValue fields.

The test extends the existing test.NullMsg fixture with:

repeated google.protobuf.NullValue null_values = 7;

It then verifies both supported well-known-type root paths already used by the ProtoJSON tests:

  • parsed .proto root
  • JSON descriptor root

For each root, the test checks both directions:

  • fromJson accepts nullValues: [null, null] and parses it as [0, 0]
  • toJson serializes [0, 0] back as nullValues: [null, null]

This specifically covers the bug where repeated null elements were rejected before the existing readEnum handling could convert google.protobuf.NullValue from null to NULL_VALUE.

Existing tests continue to cover the general rule that ordinary repeated null elements are rejected, so this change only adds the documented google.protobuf.NullValue exception.

@alexander-fenster
alexander-fenster merged commit ad0b9bb into protobufjs:master Jul 7, 2026
5 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 7, 2026
zeekay pushed a commit to hanzoai/protobuf.js that referenced this pull request Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants