summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Stepanov <penguinolog@users.noreply.github.com>2023-04-12 09:43:26 +0200
committerGitHub <noreply@github.com>2023-04-12 09:43:26 +0200
commit9f748c7fe98c20a6c1b55e28344a57b43209b046 (patch)
tree8851f1fa6e4f3ff114df72e6eba6c652a6b79e2e
parented8074910d54d510ba30829c6bb7ed4c3b3e0a55 (diff)
downloadurwid-9f748c7fe98c20a6c1b55e28344a57b43209b046.tar.gz
Fix empty markup handling (#536)
* not switching to Unicode-only at this moment, so make simple Fix #408 Co-authored-by: Aleksei Stepanov <alekseis@nvidia.com>
-rw-r--r--urwid/tests/test_util.py7
-rw-r--r--urwid/util.py5
2 files changed, 11 insertions, 1 deletions
diff --git a/urwid/tests/test_util.py b/urwid/tests/test_util.py
index eeae2f9..06de8c8 100644
--- a/urwid/tests/test_util.py
+++ b/urwid/tests/test_util.py
@@ -227,3 +227,10 @@ class PortabilityTest(unittest.TestCase):
f"Locale restore impossible, probably locale not supported by system (libc ignores this error).\n"
f"{exc}"
)
+
+
+class TestEmptyMarkup(unittest.TestCase):
+ def test_001_empty(self):
+ text = urwid.Text('')
+ text.set_text(text.get_text())
+ self.assertEqual("", text.text)
diff --git a/urwid/util.py b/urwid/util.py
index de5bae2..9505d74 100644
--- a/urwid/util.py
+++ b/urwid/util.py
@@ -382,7 +382,10 @@ def decompose_tagmarkup(tm):
tl, al = _tagmarkup_recurse(tm, None)
# join as unicode or bytes based on type of first element
- text = tl[0][:0].join(tl)
+ if tl:
+ text = tl[0][:0].join(tl)
+ else:
+ text = ""
if al and al[-1][0] is None:
del al[-1]