Skip to content

Commit

Permalink
imp - The \0 characters should be compensated properly
Browse files Browse the repository at this point in the history
---

The GetWrappedSentencesByWords() function should be able to compensate \0 character occurrences properly. This fixes crashing TUIs, in particular, RSS TUI with The Verge on Nitrocid KS.

---

Type: imp
Breaking: False
Doc Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Mar 10, 2024
1 parent a512840 commit 277df15
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 13 additions & 0 deletions Terminaux.Tests/Base/ConsoleQueryingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ public void TestGetWrappedSentencesByWordsIndented()
sentences[6].ShouldBe("sim");
}

/// <summary>
/// Tests getting wrapped sentences
/// </summary>
[TestMethod]
[Description("Querying")]
public void TestGetWrappedSentencesByWordsEdgeCase()
{
var sentences = ConsoleMisc.GetWrappedSentencesByWords("-------------------------------------------------------------------\r\n\r\nTest text\n \n\n Test text 2.", 30);
sentences.ShouldNotBeNull();
sentences.ShouldNotBeEmpty();
sentences.Length.ShouldBe(8);
}

/// <summary>
/// Tests truncating...
/// </summary>
Expand Down
5 changes: 3 additions & 2 deletions Terminaux/Base/Extensions/ConsoleMisc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,9 @@ void CompensateLengths(string text)
CompensateLengths(word);

// Compensate the \0 characters
if (splitText[i] == '\0')
vtSeqCompensate++;
for (int c = 0; c < word.Length; c++)
if (splitText[c] == '\0')
vtSeqCompensate++;

// Append the word into the incomplete sentence builder.
int finalMaximum = maximumLength - indentLength + vtSeqCompensate;
Expand Down

0 comments on commit 277df15

Please sign in to comment.