github-advanced-security[bot] commented on code in PR #3516:
URL: https://github.com/apache/avro/pull/3516#discussion_r2426280966
##########
lang/csharp/src/apache/main/CodeGen/CodeGen.cs:
##########
@@ -133,10 +136,31 @@
/// <param name="namespaceMapping">namespace mapping key value
pairs.</param>
public virtual void AddSchema(string schemaText,
IEnumerable<KeyValuePair<string, string>> namespaceMapping = null)
{
+ var originalSchemaText = schemaText;
Review Comment:
## Useless assignment to local variable
This assignment to [originalSchemaText](1) is useless, since its value is
never read.
[Show more
details](https://github.com/apache/avro/security/code-scanning/3352)
##########
lang/csharp/src/apache/main/CodeGen/CodeGen.cs:
##########
@@ -133,10 +136,31 @@
/// <param name="namespaceMapping">namespace mapping key value
pairs.</param>
public virtual void AddSchema(string schemaText,
IEnumerable<KeyValuePair<string, string>> namespaceMapping = null)
{
+ var originalSchemaText = schemaText;
// Map namespaces
- schemaText = ReplaceMappedNamespacesInSchema(schemaText,
namespaceMapping);
- Schema schema = Schema.Parse(schemaText);
- Schemas.Add(schema);
+ var namespaceAdjustedSchemaText =
ReplaceMappedNamespacesInSchema(schemaText, namespaceMapping);
+ Schema namspaceAdjustedSchema =
Schema.Parse(namespaceAdjustedSchemaText);
+ Schemas.Add(namspaceAdjustedSchema);
+
+ AddReplacedNamespaceMappings(namespaceMapping);
+ }
+
+ /// <summary>
+ /// Adds namespace mappings in the schema text to
ReplacedNamespaceMappings, so that they can be reversed later to keep the
original schema text intact within the "Schema" property.
+ /// </summary>
+ /// <param name="namespaceMapping"></param>
+ protected void
AddReplacedNamespaceMappings(IEnumerable<KeyValuePair<string, string>>
namespaceMapping)
+ {
+ if(namespaceMapping == null)
+ return;
+
+ foreach (var item in namespaceMapping)
+ {
+ if (ReplacedNamespaceMappings.ContainsKey(item.Key))
+ continue;
+
+ ReplacedNamespaceMappings.Add(item.Key, item.Value);
+ }
Review Comment:
## Missed opportunity to use Where
This foreach loop [implicitly filters its target sequence](1) - consider
filtering the sequence explicitly using '.Where(...)'.
[Show more
details](https://github.com/apache/avro/security/code-scanning/3349)
##########
lang/csharp/src/apache/test/AvroGen/AvroGenHelper.cs:
##########
@@ -230,6 +231,20 @@
{
// Read record's schema object
Assert.That(record.Schema, Is.Not.Null);
+
+ if(namespaceMapping is not null)
+ {
+ var schema = record.Schema.ToString();
+ foreach (var mapping in namespaceMapping)
+ {
+ if(mapping.Key == mapping.Value)
+ continue;
+
+ Assert.That(schema,
Does.Contain($"\"namespace\":\"{mapping.Key}\""));
+ Assert.That(schema,
Does.Not.Contain($"\"namespace\":\"{mapping.Value}\""));
+ }
Review Comment:
## Missed opportunity to use Where
This foreach loop [implicitly filters its target sequence](1) - consider
filtering the sequence explicitly using '.Where(...)'.
[Show more
details](https://github.com/apache/avro/security/code-scanning/3350)
--
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]