Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-dmxc committed Oct 2, 2024
1 parent 1aabd78 commit 5ecf37a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions RDMSharp/Metadata/JSON/OneOfTypes/StringType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ void parse(Encoding encoder)
takenBytesCount = byteLength;
charLength = str.Length;
bool repeatParse = false;
if (MaxLength.HasValue && MaxLength < charLength)
if (MaxLength.HasValue && MaxLength.Value < charLength)
{
charLength = (int)MaxLength.Value;
repeatParse = true;
}
if (MaxBytes.HasValue && MaxBytes < byteLength)
if (MaxBytes.HasValue && MaxBytes.Value < byteLength)
{
byteLength = (int)MaxBytes.Value;
repeatParse = true;
Expand Down
9 changes: 9 additions & 0 deletions RDMSharpTests/Metadata/JSON/TestStringType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ public void TestParseBadFormatedData1()
dataTree = stringType.ParseDataToPayload(ref data);
Assert.That(dataTree.Value, Is.EqualTo(string.Empty));
Assert.That(dataTree.Issues, Has.Length.EqualTo(1));

data = new byte[] { 195, 132, 195, 132, 195, 132, 195, 132, 0 };
dataTree = stringType.ParseDataToPayload(ref data);
Assert.That(dataTree.Value, Is.EqualTo("ÄÄÄÄ"));
Assert.That(dataTree.Issues, Has.Length.EqualTo(1));
data = new byte[] { 195, 132, 195, 132, 195, 132, 195, 132, 119, 119, 0 };
dataTree = stringType.ParseDataToPayload(ref data);
Assert.That(dataTree.Value, Is.EqualTo("ÄÄÄÄ"));
Assert.That(dataTree.Issues, Has.Length.EqualTo(1));
}
[Test]
public void TestParseBadFormatedData2()
Expand Down

0 comments on commit 5ecf37a

Please sign in to comment.