This is an automated email from the ASF dual-hosted git repository. blachniet pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/avro.git
commit e6479eae59aa9d83d6effc7284e5a3821c5e8c14 Author: Brian Lachniet <[email protected]> AuthorDate: Sun Aug 18 12:08:52 2019 -0400 AVRO-2454: Fix CA1307 - Specify StringComparison --- lang/csharp/Avro.ruleset | 1 - lang/csharp/src/apache/main/File/DataFileWriter.cs | 2 +- lang/csharp/src/apache/main/Generic/GenericEnum.cs | 4 +++- lang/csharp/src/apache/main/Protocol/Message.cs | 2 +- lang/csharp/src/apache/main/Protocol/Protocol.cs | 6 ++++-- lang/csharp/src/apache/main/Schema/EnumSchema.cs | 9 ++++++++- lang/csharp/src/apache/main/Schema/PrimitiveSchema.cs | 7 ++++++- lang/csharp/src/apache/main/Schema/Property.cs | 10 +++++++--- lang/csharp/src/apache/main/Schema/Schema.cs | 7 ++++--- 9 files changed, 34 insertions(+), 14 deletions(-) diff --git a/lang/csharp/Avro.ruleset b/lang/csharp/Avro.ruleset index 329a5fc..1f12d7f 100644 --- a/lang/csharp/Avro.ruleset +++ b/lang/csharp/Avro.ruleset @@ -25,7 +25,6 @@ We disabled these rules initially to get the code analyzers installed in the project. --> <Rule Id="CA1062" Action="Info" /> - <Rule Id="CA1307" Action="Info" /> <Rule Id="CA1507" Action="Info" /> <Rule Id="CA1707" Action="Info" /> <Rule Id="CA1710" Action="Info" /> diff --git a/lang/csharp/src/apache/main/File/DataFileWriter.cs b/lang/csharp/src/apache/main/File/DataFileWriter.cs index 897ef6e..234f205 100644 --- a/lang/csharp/src/apache/main/File/DataFileWriter.cs +++ b/lang/csharp/src/apache/main/File/DataFileWriter.cs @@ -107,7 +107,7 @@ namespace Avro.File /// <inheritdoc/> public bool IsReservedMeta(string key) { - return key.StartsWith(DataFileConstants.MetaDataReserved); + return key.StartsWith(DataFileConstants.MetaDataReserved, StringComparison.Ordinal); } /// <inheritdoc/> diff --git a/lang/csharp/src/apache/main/Generic/GenericEnum.cs b/lang/csharp/src/apache/main/Generic/GenericEnum.cs index d80ecff..1e81304 100644 --- a/lang/csharp/src/apache/main/Generic/GenericEnum.cs +++ b/lang/csharp/src/apache/main/Generic/GenericEnum.cs @@ -57,7 +57,9 @@ namespace Avro.Generic public override bool Equals(object obj) { if (obj == this) return true; - return (obj != null && obj is GenericEnum) ? Value.Equals((obj as GenericEnum).Value) : false; + return (obj != null && obj is GenericEnum) + ? Value.Equals((obj as GenericEnum).Value, System.StringComparison.Ordinal) + : false; } /// <inheritdoc/> diff --git a/lang/csharp/src/apache/main/Protocol/Message.cs b/lang/csharp/src/apache/main/Protocol/Message.cs index 9df50ec..34edd0a 100644 --- a/lang/csharp/src/apache/main/Protocol/Message.cs +++ b/lang/csharp/src/apache/main/Protocol/Message.cs @@ -186,7 +186,7 @@ namespace Avro if (!(obj is Message)) return false; Message that = obj as Message; - return this.Name.Equals(that.Name) && + return this.Name.Equals(that.Name, StringComparison.Ordinal) && this.Request.Equals(that.Request) && areEqual(this.Response, that.Response) && areEqual(this.Error, that.Error); diff --git a/lang/csharp/src/apache/main/Protocol/Protocol.cs b/lang/csharp/src/apache/main/Protocol/Protocol.cs index 51c672c..2665823 100644 --- a/lang/csharp/src/apache/main/Protocol/Protocol.cs +++ b/lang/csharp/src/apache/main/Protocol/Protocol.cs @@ -222,8 +222,10 @@ namespace Avro Protocol that = obj as Protocol; - return this.Name.Equals(that.Name) && this.Namespace.Equals(that.Namespace) && - TypesEquals(that.Types) && MessagesEquals(that.Messages); + return this.Name.Equals(that.Name, StringComparison.Ordinal) + && this.Namespace.Equals(that.Namespace, StringComparison.Ordinal) + && TypesEquals(that.Types) + && MessagesEquals(that.Messages); } /// <summary> diff --git a/lang/csharp/src/apache/main/Schema/EnumSchema.cs b/lang/csharp/src/apache/main/Schema/EnumSchema.cs index 4344e41..f5b72e0 100644 --- a/lang/csharp/src/apache/main/Schema/EnumSchema.cs +++ b/lang/csharp/src/apache/main/Schema/EnumSchema.cs @@ -178,7 +178,14 @@ namespace Avro EnumSchema that = obj as EnumSchema; if (SchemaName.Equals(that.SchemaName) && Count == that.Count) { - for (int i = 0; i < Count; i++) if (!Symbols[i].Equals(that.Symbols[i])) return false; + for (int i = 0; i < Count; i++) + { + if (!Symbols[i].Equals(that.Symbols[i], StringComparison.Ordinal)) + { + return false; + } + } + return areEqual(that.Props, this.Props); } } diff --git a/lang/csharp/src/apache/main/Schema/PrimitiveSchema.cs b/lang/csharp/src/apache/main/Schema/PrimitiveSchema.cs index 703519c..13485d1 100644 --- a/lang/csharp/src/apache/main/Schema/PrimitiveSchema.cs +++ b/lang/csharp/src/apache/main/Schema/PrimitiveSchema.cs @@ -45,7 +45,12 @@ namespace Avro public static PrimitiveSchema NewInstance(string type, PropertyMap props = null) { const string q = "\""; - if (type.StartsWith(q) && type.EndsWith(q)) type = type.Substring(1, type.Length - 2); + if (type.StartsWith(q, StringComparison.Ordinal) + && type.EndsWith(q, StringComparison.Ordinal)) + { + type = type.Substring(1, type.Length - 2); + } + switch (type) { case "null": diff --git a/lang/csharp/src/apache/main/Schema/Property.cs b/lang/csharp/src/apache/main/Schema/Property.cs index 50ca739..8ffd6bf 100644 --- a/lang/csharp/src/apache/main/Schema/Property.cs +++ b/lang/csharp/src/apache/main/Schema/Property.cs @@ -15,9 +15,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +using System; using System.Collections.Generic; -using Newtonsoft.Json.Linq; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; namespace Avro { @@ -61,7 +62,10 @@ namespace Avro string oldValue; if (TryGetValue(key, out oldValue)) { - if (!oldValue.Equals(value)) throw new AvroException("Property cannot be overwritten: " + key); + if (!oldValue.Equals(value, StringComparison.Ordinal)) + { + throw new AvroException("Property cannot be overwritten: " + key); + } } else Add(key, value); @@ -100,7 +104,7 @@ namespace Avro { if (!that.ContainsKey(pair.Key)) return false; - if (!pair.Value.Equals(that[pair.Key])) + if (!pair.Value.Equals(that[pair.Key], StringComparison.Ordinal)) return false; } return true; diff --git a/lang/csharp/src/apache/main/Schema/Schema.cs b/lang/csharp/src/apache/main/Schema/Schema.cs index fe0729a..046151d 100644 --- a/lang/csharp/src/apache/main/Schema/Schema.cs +++ b/lang/csharp/src/apache/main/Schema/Schema.cs @@ -183,9 +183,9 @@ namespace Avro { string type = (string)jtype; - if (type.Equals("array")) + if (type.Equals("array", StringComparison.Ordinal)) return ArraySchema.NewInstance(jtok, props, names, encspace); - if (type.Equals("map")) + if (type.Equals("map", StringComparison.Ordinal)) return MapSchema.NewInstance(jtok, props, names, encspace); Schema schema = PrimitiveSchema.NewInstance((string)type, props); @@ -224,7 +224,8 @@ namespace Avro try { - bool IsArray = json.StartsWith("[") && json.EndsWith("]"); + bool IsArray = json.StartsWith("[", StringComparison.Ordinal) + && json.EndsWith("]", StringComparison.Ordinal); JContainer j = IsArray ? (JContainer)JArray.Parse(json) : (JContainer)JObject.Parse(json); return ParseJson(j, names, encspace);
