AVRO-4346: [csharp] Validate enum symbols and protocol names at parse time - #3949
Open
iemejia wants to merge 1 commit into
Open
AVRO-4346: [csharp] Validate enum symbols and protocol names at parse time#3949iemejia wants to merge 1 commit into
iemejia wants to merge 1 commit into
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
EnumSchema.NewInstanceonly checked for duplicates and never calledValidateSymbolName(that ran only on the programmaticCreate()path). An out-of-spec symbol (leading digit, space, punctuation, …) was carried through and spliced as an enum member identifier by the generator.Protocol.Parsenever validated the protocol name, which is emitted as generated class names.Fix
EnumSchema.NewInstance: callValidateSymbolNameon each symbol, surfacing aSchemaParseExceptionwith the JSON path (consistent with the neighbouring duplicate-symbol error).Protocol.Parse: validate the protocol name viaSchemaName.ValidateName(name, "protocol"), surfacing aProtocolParseException(consistent with how message-name validation is surfaced inMessage.Parse).Tests
Adds
TestBasiccases for out-of-spec enum symbols (leading digit / space / hyphen) and aTestInvalidProtocolNamecase set (leading digit / space / injection-style name). Full C# suite passes (1533 tests, 0 failures).JIRA: https://issues.apache.org/jira/browse/AVRO-4346