[ 
https://issues.apache.org/jira/browse/AVRO-4314?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18098230#comment-18098230
 ] 

ASF subversion and git services commented on AVRO-4314:
-------------------------------------------------------

Commit 787adb119c707815e8c6e75289a40a8ec989bc65 in avro's branch 
refs/heads/main from Ismaël Mejía
[ https://gitbox.apache.org/repos/asf?p=avro.git;h=787adb119c ]

AVRO-4314: [csharp] Validate names against the Avro name grammar (#3895)

* AVRO-4314: [csharp] Validate names against the Avro name grammar

Record/fixed/enum names, record field names and protocol message names
were accepted verbatim when parsing, unlike enum symbols which were
already validated. Because the code generator splices some of these
values directly into generated C# source (for example protocol message
names into a case label and field names into Get/Put switch bodies), an
out-of-spec name produced malformed or unexpected generated code.

Add a shared, Unicode-aware name validator (first character a letter or
'_', remaining characters letters, digits or '_') and apply it to
schema names, field names and message names during parsing. The rule is
Unicode-aware to preserve the existing support for non-ASCII names, and
namespaces are intentionally not validated because the code generator's
namespace-mapping feature rewrites them to C#-specific values (such as
"@return") and re-parses the schema. Add negative tests for invalid
field, record and message names.

* AVRO-4314: [csharp] Validate field aliases and sanitize name errors

Address review feedback:
- Validate record field aliases with the same rule as field names, since
  aliases participate in schema resolution and are names per the Avro
  grammar. Previously they were accepted verbatim.
- Escape control characters (and quote the value) when embedding an
  invalid name in the SchemaParseException message, so a crafted name
  containing newlines or other control characters cannot produce
  multi-line or ambiguous error output.

Add a negative test for an invalid field alias.

* AVRO-4314: [csharp] Handle supplementary-plane characters in names

Address review feedback: ValidateName inspected individual UTF-16 code
units, which rejected valid supplementary-plane letters and digits that
are encoded as surrogate pairs. Iterate by Unicode scalar value using
the char.IsLetter(string, int) / char.IsLetterOrDigit(string, int)
overloads and advance past surrogate pairs. Add a test that a name
containing a supplementary-plane letter (U+20000) is accepted.

> [csharp] Validate names against the Avro name grammar at parse time
> -------------------------------------------------------------------
>
>                 Key: AVRO-4314
>                 URL: https://issues.apache.org/jira/browse/AVRO-4314
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: csharp
>            Reporter: Ismaël Mejía
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> The Avro specification requires record/enum/fixed names, field names, enum 
> symbols, and protocol message names to match `[A-Za-z_][A-Za-z0-9_]*` (with 
> dotted namespaces). The Java SDK enforces this during parsing, but the C# SDK 
> does not validate all of these.
> In the C# SDK only enum symbols are validated (EnumSchema); record/fixed/enum 
> names, namespaces, field names, and protocol message names are accepted 
> verbatim (SchemaName, Field, Message). Because the C# code generator splices 
> some of these values directly into generated source (for example protocol 
> message names into a `case "..."` label and field names into Get/Put switch 
> bodies via CodeSnippetExpression), an out-of-spec name produces malformed or 
> unexpected generated C# code.
> Proposal: validate names, field names, and message names against the Avro 
> name grammar during schema/protocol parsing in the C# SDK, matching the Java 
> SDK behavior, and add tests covering rejection of out-of-spec values.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to