From 2a8b0f201c531ae022e29c2515411aa7f4867a5b Mon Sep 17 00:00:00 2001 From: Itay Neeman Date: Tue, 7 Jun 2016 23:54:20 +0000 Subject: [PATCH] Handle cases where we get an empty key for an s:dict entry When EAI sends us s:dict entries (with nested s:key nodes), we parse them as a dictionary in C#. However, it turns out the API can send us a case where the value for the s:key node is actually the empty string, which we do not expect and actually have a code contract to protect against. In that case, we will change it from the empty string to the string called "empty" to be explicit about it. Since there can only be one empty key per level (otherwise it would be a serious API error), this is a reasonable workaround. --- src/Splunk.Client/Splunk/Client/AtomEntry.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Splunk.Client/Splunk/Client/AtomEntry.cs b/src/Splunk.Client/Splunk/Client/AtomEntry.cs index ae9a60c2..77637a80 100644 --- a/src/Splunk.Client/Splunk/Client/AtomEntry.cs +++ b/src/Splunk.Client/Splunk/Client/AtomEntry.cs @@ -389,6 +389,21 @@ static async Task ParseDictionaryAsync(XmlReader reader, int level) string propertyName; dynamic propertyValue; + // There are cases where the server sends us bad values for "s:key", namely + // the empty string. This happens for example when we get back the metadata for + // a search job which contains an "eval". In these cases, we simply replace the + // empty string with a literal string called "empty", so that we know where it came + // from. + // + // The risk with this fix is that we will have multiple empty keys at the same + // level, and thus using "empty" would clash. However, this would be an even more + // serious error on the part of the API, as it would mean we have no way to disambiguate + // those two entries. As such, we feel it is safe. + if (names[names.Length - 1] == "") + { + names[names.Length - 1] = "empty"; + } + for (int i = 0; i < names.Length - 1; i++) { propertyName = NormalizePropertyName(names[i]);