Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/SeqCli/Apps/Hosting/AppContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Newtonsoft.Json;
Expand All @@ -35,7 +36,7 @@ partial class AppContainer : IAppHost, IDisposable
readonly SeqApp _seqApp;
readonly AppLoader _loader;

static readonly Regex HexDigits = HexDigitsRegex();
static readonly Regex NonZeroHex = NonZeroHexRegex();

readonly JsonSerializer _serializer = JsonSerializer.Create(new JsonSerializerSettings
{
Expand Down Expand Up @@ -183,7 +184,7 @@ static bool IsValidHexIdentifier(JToken? value, int requiredChars)
if (value?.Value<string>() is not { } id)
return false;

return id.Length == requiredChars && HexDigits.IsMatch(id);
return id.Length == requiredChars && NonZeroHex.IsMatch(id);
}

public void StartPublishing(TextWriter inputWriter)
Expand All @@ -198,7 +199,6 @@ public void StopPublishing()
pjson.Stop();
}

// Technically,
[GeneratedRegex("^[0-9a-f]*$")]
private static partial Regex HexDigitsRegex();
}
[GeneratedRegex("^0*[1-9a-f][0-9a-f]*$")]
private static partial Regex NonZeroHexRegex();
}
14 changes: 14 additions & 0 deletions test/SeqCli.Tests/Apps/AppContainerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ public void RemovesShortTraceAndSpanIds()
Assert.Empty(jo);
}

[Fact]
public void RemovesZeroTraceAndSpanIds()
{
var jo = new JObject
{
["@tr"] = "00000000000000000000000000000000",
["@sp"] = "0000000000000000",
["@ps"] = "0000000000000000"
};
Assert.NotEmpty(jo);
AppContainer.SanitizeTraceIdentifiers(jo);
Assert.Empty(jo);
}

[Fact]
public void PreservesValidTraceAndSpanIds()
{
Expand Down
Loading