Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add test cases for short and long subject whitespace validation
Expanded tests to include separate validations for short (<16 chars) and long (≥16 chars) subject paths, with specific checks for whitespace handling.
  • Loading branch information
mtmk committed Dec 15, 2025
commit 4aaf9a60908ba2a512c496c96b39a8a0f095e009
18 changes: 16 additions & 2 deletions tests/NATS.Client.CoreUnit.Tests/ProtocolWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void WritePublish_WildcardSubject_DoesNotThrow(string subject)
action.Should().NotThrow();
}

// Whitespace validation for subjects
// Whitespace validation for subjects (short path < 16 chars)
[Theory]
[InlineData("foo bar")]
[InlineData("foo\tbar")]
Expand All @@ -49,7 +49,21 @@ public void WritePublish_WildcardSubject_DoesNotThrow(string subject)
[InlineData("\tfoo")]
[InlineData("\rfoo")]
[InlineData("\nfoo")]
public void WritePublish_SubjectWithWhitespace_Throws(string subject)
public void WritePublish_ShortSubjectWithWhitespace_Throws(string subject)
{
using var writer = new NatsBufferWriter<byte>();
var action = () => _protocolWriter.WritePublish(writer, subject, null, null, ReadOnlyMemory<byte>.Empty);
action.Should().Throw<NatsException>().WithMessage("Subject is invalid.");
}

// Whitespace validation for subjects (long path >= 16 chars, SIMD)
[Theory]
[InlineData("foo.bar.baz.qux witespace")]
[InlineData("foo.bar.baz.qux\twithtab")]
[InlineData("foo.bar.baz.qux\rwithcr")]
[InlineData("foo.bar.baz.qux\nwithlf")]
[InlineData(" foo.bar.baz.qux.start")]
public void WritePublish_LongSubjectWithWhitespace_Throws(string subject)
{
using var writer = new NatsBufferWriter<byte>();
var action = () => _protocolWriter.WritePublish(writer, subject, null, null, ReadOnlyMemory<byte>.Empty);
Expand Down
Loading