Skip to content

AVRO-4346: [csharp] Validate enum symbols and protocol names at parse time - #3949

Open
iemejia wants to merge 1 commit into
apache:mainfrom
iemejia:AVRO-4346-csharp-enum-protocol-validation
Open

AVRO-4346: [csharp] Validate enum symbols and protocol names at parse time#3949
iemejia wants to merge 1 commit into
apache:mainfrom
iemejia:AVRO-4346-csharp-enum-protocol-validation

Conversation

@iemejia

@iemejia iemejia commented Aug 22, 2026

Copy link
Copy Markdown
Member

What

AVRO-4314 added Avro name-grammar validation for record/fixed/enum names, field names and aliases, and message names. This closes two parse-time paths it left unvalidated, which are then emitted verbatim as identifiers by the C# code generator:

  1. Enum symbols read from JSONEnumSchema.NewInstance only checked for duplicates and never called ValidateSymbolName (that ran only on the programmatic Create() path). An out-of-spec symbol (leading digit, space, punctuation, …) was carried through and spliced as an enum member identifier by the generator.
  2. Protocol namesProtocol.Parse never validated the protocol name, which is emitted as generated class names.

Fix

  • EnumSchema.NewInstance: call ValidateSymbolName on each symbol, surfacing a SchemaParseException with the JSON path (consistent with the neighbouring duplicate-symbol error).
  • Protocol.Parse: validate the protocol name via SchemaName.ValidateName(name, "protocol"), surfacing a ProtocolParseException (consistent with how message-name validation is surfaced in Message.Parse).

Tests

Adds TestBasic cases for out-of-spec enum symbols (leading digit / space / hyphen) and a TestInvalidProtocolName case set (leading digit / space / injection-style name). Full C# suite passes (1533 tests, 0 failures).

JIRA: https://issues.apache.org/jira/browse/AVRO-4346

… time

AVRO-4314 added Avro name-grammar validation for record/fixed/enum names,
field names and aliases, and message names, but two parse-time paths were
left unvalidated:

- Enum symbols read from JSON: EnumSchema.NewInstance only checked for
  duplicates and never called ValidateSymbolName (that ran only on the
  programmatic Create() path). An out-of-spec symbol was carried through
  and emitted verbatim as an enum member identifier by the code generator.
- Protocol names: Protocol.Parse never validated the protocol name, which
  is emitted as generated class names.

Validate enum symbols on the JSON parse path (surfacing a SchemaParseException
with the JSON path, consistent with the duplicate-symbol error) and validate
the protocol name via SchemaName.ValidateName (surfacing a ProtocolParseException,
consistent with message-name handling). Adds tests for out-of-spec enum symbols
and protocol names.
@github-actions github-actions Bot added the C# label Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant