up
This commit is contained in:
@@ -28,7 +28,7 @@ public static class RiskProfileCanonicalizer
|
||||
|
||||
public static byte[] CanonicalizeToUtf8(ReadOnlySpan<byte> utf8Json)
|
||||
{
|
||||
using var doc = JsonDocument.Parse(utf8Json, DocOptions);
|
||||
using var doc = JsonDocument.Parse(utf8Json.ToArray(), DocOptions);
|
||||
var canonical = CanonicalizeElement(doc.RootElement);
|
||||
return Encoding.UTF8.GetBytes(canonical);
|
||||
}
|
||||
@@ -103,11 +103,11 @@ public static class RiskProfileCanonicalizer
|
||||
}
|
||||
else if (IsSeverityOverrides(path))
|
||||
{
|
||||
items = items.OrderBy(GetWhenThenKey, StringComparer.Ordinal).ToList();
|
||||
items = items.OrderBy(GetWhenThenKeyFromNode, StringComparer.Ordinal).ToList();
|
||||
}
|
||||
else if (IsDecisionOverrides(path))
|
||||
{
|
||||
items = items.OrderBy(GetWhenThenKey, StringComparer.Ordinal).ToList();
|
||||
items = items.OrderBy(GetWhenThenKeyFromNode, StringComparer.Ordinal).ToList();
|
||||
}
|
||||
|
||||
array.Clear();
|
||||
@@ -303,6 +303,19 @@ public static class RiskProfileCanonicalizer
|
||||
return when + "|" + then;
|
||||
}
|
||||
|
||||
private static string GetWhenThenKeyFromNode(JsonNode? node)
|
||||
{
|
||||
if (node is null) return string.Empty;
|
||||
var obj = node.AsObject();
|
||||
var when = obj.TryGetPropertyValue("when", out var whenNode) && whenNode is not null ? whenNode.ToJsonString() : string.Empty;
|
||||
var then = obj.TryGetPropertyValue("set", out var setNode) && setNode is not null
|
||||
? setNode.ToJsonString()
|
||||
: obj.TryGetPropertyValue("action", out var actionNode) && actionNode is not null
|
||||
? actionNode.ToJsonString()
|
||||
: string.Empty;
|
||||
return when + "|" + then;
|
||||
}
|
||||
|
||||
private static bool IsSignals(IReadOnlyList<string> path)
|
||||
=> path.Count >= 1 && path[^1] == "signals";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user