From 3e711ebe7f3fc5efb3562ea617e6bf1303b1e3ce Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sat, 13 Apr 2024 00:37:21 +0200 Subject: [PATCH] Fix word counter bug (#1816) --- novelwriter/text/counting.py | 1 + tests/test_text/test_core_counting.py | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/novelwriter/text/counting.py b/novelwriter/text/counting.py index 59974ee5..f63ee2a6 100644 --- a/novelwriter/text/counting.py +++ b/novelwriter/text/counting.py @@ -57,6 +57,7 @@ def preProcessText(text: str, keepHeaders: bool = True) -> list[str]: continue if line[0] == ">": line = line.lstrip(">").lstrip(" ") + if line: # Above check can return empty line (Issue #1816) if line[-1] == "<": line = line.rstrip("<").rstrip(" ") if "[" in line: diff --git a/tests/test_text/test_core_counting.py b/tests/test_text/test_core_counting.py index bab0596e..0c6bd448 100644 --- a/tests/test_text/test_core_counting.py +++ b/tests/test_text/test_core_counting.py @@ -29,7 +29,7 @@ from novelwriter.text.counting import bodyTextCounter, preProcessText, standardC def testTextCounting_preProcessText(): """Test the text preprocessor for counters.""" # Not Text - assert preProcessText(None) == [] + assert preProcessText(None) == [] # type: ignore # No Text assert preProcessText("") == [] @@ -81,6 +81,10 @@ def testTextCounting_standardCounter(): assert standardCounter(None) == (0, 0, 0) # type: ignore assert standardCounter(1234) == (0, 0, 0) # type: ignore + # Test Corner Cases, Bug #1816 + assert standardCounter("> ") == (0, 0, 0) + assert standardCounter(" <") == (0, 0, 0) + # General Text cC, wC, pC = standardCounter(( "#! Title\n\n" @@ -182,7 +186,7 @@ def testTextCounting_standardCounter(): def testTextCounting_bodyTextCounter(): """Test the body text counter.""" # Not Text - assert bodyTextCounter(None) == (0, 0, 0) + assert bodyTextCounter(None) == (0, 0, 0) # type: ignore # General Text wC, cC, sC = bodyTextCounter((