From c5debf12d46058542a30d6092a89e063b60025b1 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Wed, 19 Feb 2014 20:29:22 -0500 Subject: [PATCH] Fix bugs in search rule matching --- NBTModel/Search/SearchRule.cs | 142 ++++++++++++++++++---------------- 1 file changed, 77 insertions(+), 65 deletions(-) diff --git a/NBTModel/Search/SearchRule.cs b/NBTModel/Search/SearchRule.cs index 245eb23..dcb985a 100644 --- a/NBTModel/Search/SearchRule.cs +++ b/NBTModel/Search/SearchRule.cs @@ -169,26 +169,30 @@ namespace NBTExplorer.Model.Search { TagDataNode childNode = GetChild(container, Name); T data = LookupTag(container, Name); + if (data == null) + return false; - if (data != null) { - switch (Operator) { - case NumericOperator.Equals: - if (data.ToTagLong() != Value) - return false; - break; - case NumericOperator.NotEquals: - if (data.ToTagLong() == Value) - return false; - break; - case NumericOperator.GreaterThan: - if (data.ToTagLong() <= Value) - return false; - break; - case NumericOperator.LessThan: - if (data.ToTagLong() >= Value) - return false; - break; - } + switch (Operator) { + case NumericOperator.Equals: + if (data.ToTagLong() != Value) + return false; + break; + case NumericOperator.NotEquals: + if (data.ToTagLong() == Value) + return false; + break; + case NumericOperator.GreaterThan: + if (data.ToTagLong() <= Value) + return false; + break; + case NumericOperator.LessThan: + if (data.ToTagLong() >= Value) + return false; + break; + case NumericOperator.Any: + break; + default: + return false; } if (!matchedNodes.Contains(childNode)) @@ -226,26 +230,30 @@ namespace NBTExplorer.Model.Search { TagDataNode childNode = GetChild(container, Name); T data = LookupTag(container, Name); + if (data == null) + return false; - if (data != null) { - switch (Operator) { - case NumericOperator.Equals: - if (data.ToTagDouble() != Value) - return false; - break; - case NumericOperator.NotEquals: - if (data.ToTagDouble() == Value) - return false; - break; - case NumericOperator.GreaterThan: - if (data.ToTagDouble() <= Value) - return false; - break; - case NumericOperator.LessThan: - if (data.ToTagDouble() >= Value) - return false; - break; - } + switch (Operator) { + case NumericOperator.Equals: + if (data.ToTagDouble() != Value) + return false; + break; + case NumericOperator.NotEquals: + if (data.ToTagDouble() == Value) + return false; + break; + case NumericOperator.GreaterThan: + if (data.ToTagDouble() <= Value) + return false; + break; + case NumericOperator.LessThan: + if (data.ToTagDouble() >= Value) + return false; + break; + case NumericOperator.Any: + break; + default: + return false; } if (!matchedNodes.Contains(childNode)) @@ -276,34 +284,38 @@ namespace NBTExplorer.Model.Search { TagDataNode childNode = GetChild(container, Name); TagNodeString data = LookupTag(container, Name); + if (data == null) + return false; - if (data != null) { - switch (Operator) { - case StringOperator.Equals: - if (data.ToTagString().Data != Value) - return false; - break; - case StringOperator.NotEquals: - if (data.ToTagString().Data == Value) - return false; - break; - case StringOperator.Contains: - if (!data.ToTagString().Data.Contains(Value)) - return false; - break; - case StringOperator.NotContains: - if (data.ToTagString().Data.Contains(Value)) - return false; - break; - case StringOperator.StartsWith: - if (!data.ToTagString().Data.StartsWith(Value)) - return false; - break; - case StringOperator.EndsWith: - if (!data.ToTagString().Data.EndsWith(Value)) - return false; - break; - } + switch (Operator) { + case StringOperator.Equals: + if (data.ToTagString().Data != Value) + return false; + break; + case StringOperator.NotEquals: + if (data.ToTagString().Data == Value) + return false; + break; + case StringOperator.Contains: + if (!data.ToTagString().Data.Contains(Value)) + return false; + break; + case StringOperator.NotContains: + if (data.ToTagString().Data.Contains(Value)) + return false; + break; + case StringOperator.StartsWith: + if (!data.ToTagString().Data.StartsWith(Value)) + return false; + break; + case StringOperator.EndsWith: + if (!data.ToTagString().Data.EndsWith(Value)) + return false; + break; + case StringOperator.Any: + break; + default: + return false; } if (!matchedNodes.Contains(childNode))