Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lang/csharp/src/apache/main/Protocol/Protocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ public static Protocol Parse(string jstring)
private static Protocol Parse(JToken jtok)
{
string name = JsonHelper.GetRequiredString(jtok, "protocol");
try
{
SchemaName.ValidateName(name, "protocol");
}
catch (SchemaParseException e)
{
throw new ProtocolParseException($"Invalid protocol name: {name}", e);
}
string space = JsonHelper.GetOptionalString(jtok, "namespace");
string doc = JsonHelper.GetOptionalString(jtok, "doc");

Expand Down
9 changes: 9 additions & 0 deletions lang/csharp/src/apache/main/Schema/EnumSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ internal static EnumSchema NewInstance(JToken jtok, PropertyMap props, SchemaNam
if (symbolMap.ContainsKey(s))
throw new SchemaParseException($"Duplicate symbol: {s} at '{jtok.Path}'");

try
{
ValidateSymbolName(s);
}
catch (AvroException e)
{
throw new SchemaParseException($"{e.Message} at '{jtok.Path}'", e);
}

symbolMap[s] = i++;
symbols.Add(s);
}
Expand Down
11 changes: 11 additions & 0 deletions lang/csharp/src/apache/test/Protocol/ProtocolTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@ public static void TestInvalidMessageName(string str)
Assert.Throws<ProtocolParseException>(() => Protocol.Parse(str));
}

[TestCase(@"{ ""protocol"": ""9bad"", ""types"": [], ""messages"": {} }",
TestName = "ProtocolNameLeadingDigit")]
[TestCase(@"{ ""protocol"": ""bad name"", ""types"": [], ""messages"": {} }",
TestName = "ProtocolNameWithSpace")]
[TestCase(@"{ ""protocol"": ""x; class Evil"", ""types"": [], ""messages"": {} }",
TestName = "ProtocolNameInjection")]
public static void TestInvalidProtocolName(string str)
{
Assert.Throws<ProtocolParseException>(() => Protocol.Parse(str));
}

// Protocols match
[TestCase(
@"{
Expand Down
6 changes: 6 additions & 0 deletions lang/csharp/src/apache/test/Schema/SchemaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public class SchemaTests
typeof(SchemaParseException), Description = "No name")]
[TestCase("{\"type\": \"enum\", \"name\": \"Test\", \"symbols\" : [\"AA\", \"AA\"]}",
typeof(SchemaParseException), Description = "Duplicate symbol")]
[TestCase("{\"type\": \"enum\", \"name\": \"Test\", \"symbols\" : [\"1A\"]}",
typeof(SchemaParseException), Description = "Symbol with leading digit")]
[TestCase("{\"type\": \"enum\", \"name\": \"Test\", \"symbols\" : [\"A B\"]}",
typeof(SchemaParseException), Description = "Symbol with space")]
[TestCase("{\"type\": \"enum\", \"name\": \"Test\", \"symbols\" : [\"A-B\"]}",
typeof(SchemaParseException), Description = "Symbol with hyphen")]

// Array
[TestCase("{\"type\": \"array\", \"items\": \"long\"}")]
Expand Down
Loading