Copilot commented on code in PR #3890:
URL: https://github.com/apache/avro/pull/3890#discussion_r3612679748


##########
lang/csharp/src/apache/main/Schema/SchemaName.cs:
##########
@@ -25,6 +27,76 @@ namespace Avro
     /// </summary>
     public class SchemaName
     {
+        /// <summary>
+        /// Validates that a simple (unqualified) name conforms to the Avro 
name
+        /// grammar: a non-empty string whose first character is a letter or 
'_'
+        /// and whose remaining characters are letters, digits or '_'. Letters 
and
+        /// digits are recognized in a Unicode-aware way, matching the default
+        /// behavior of the Java SDK (and the C# SDK's existing support for
+        /// non-ASCII field names). Throws <see cref="SchemaParseException"/> 
when
+        /// the name is invalid.
+        /// </summary>
+        /// <param name="name">the simple name to validate</param>
+        /// <param name="what">description of the kind of name, used in error 
messages</param>
+        internal static void ValidateName(string name, string what)
+        {
+            if (string.IsNullOrEmpty(name)
+                || !(char.IsLetter(name[0]) || name[0] == '_'))
+            {
+                throw new SchemaParseException($"Invalid {what} name: 
{Quote(name)}");
+            }
+
+            for (int i = 1; i < name.Length; i++)
+            {
+                char c = name[i];
+                if (!(char.IsLetterOrDigit(c) || c == '_'))
+                {
+                    throw new SchemaParseException($"Invalid {what} name: 
{Quote(name)}");
+                }
+            }
+        }

Review Comment:
   `ValidateName` uses `char.IsLetter(name[0])` / `char.IsLetterOrDigit(c)`, 
which operate on UTF-16 code units. That will reject valid supplementary-plane 
letters/digits (represented by surrogate pairs), despite the method’s comment 
stating Unicode-aware behavior. Consider iterating by Unicode scalar value 
using the `char.IsLetter(string,int)` / `char.IsLetterOrDigit(string,int)` 
overloads and advancing past surrogate pairs.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to