Skip to content

Commit 5a46e17

Browse files
Might as well safeguard if no protections are returned.
1 parent a931232 commit 5a46e17

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

ProtectionScan/Features/MainFeature.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -326,18 +326,23 @@ private void WriteProtectionResultNestedJson(string path, Dictionary<string, Lis
326326
// dictionary value into an entry with the base path as the key.
327327
// There is no input as far as has been tested that can result in there not being a root dictionary key
328328
// of an empty string, so this is safe.
329-
var tempValue = nestedDictionary[""];
330-
nestedDictionary.Remove("");
331-
nestedDictionary.Add(trimmedPath, tempValue);
332-
333-
// Create the output data
334-
var jsonSerializerOptions = new System.Text.Json.JsonSerializerOptions { WriteIndented = true };
335-
string serializedData = System.Text.Json.JsonSerializer.Serialize(nestedDictionary, jsonSerializerOptions);
336-
337-
// Write the output data
338-
// TODO: this prints plus symbols wrong, probably some other things too
339-
jsw.WriteLine(serializedData);
340-
jsw.Flush();
329+
// The only exception is if absolutely no protections were returned whatsoever, which is why there's a
330+
// safeguard here at all
331+
if (nestedDictionary.ContainsKey(""))
332+
{
333+
var tempValue = nestedDictionary[""];
334+
nestedDictionary.Remove("");
335+
nestedDictionary.Add(trimmedPath, tempValue);
336+
337+
// Create the output data
338+
var jsonSerializerOptions = new System.Text.Json.JsonSerializerOptions { WriteIndented = true };
339+
string serializedData = System.Text.Json.JsonSerializer.Serialize(nestedDictionary, jsonSerializerOptions);
340+
341+
// Write the output data
342+
// TODO: this prints plus symbols wrong, probably some other things too
343+
jsw.WriteLine(serializedData);
344+
jsw.Flush();
345+
}
341346
}
342347
catch (Exception ex)
343348
{

0 commit comments

Comments
 (0)