Skip to content

Commit 0a5aa0d

Browse files
committed
bugfix empty string to wcwidth() while we're here
1 parent c3cd589 commit 0a5aa0d

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

bin/update-tables.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import logging
2525
import datetime
2626
import functools
27-
import collections
2827
import unicodedata
2928
from pathlib import Path
3029
from dataclasses import field, fields, dataclass

tests/test_core.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,25 @@ def test_package_version():
4141
assert result == expected
4242

4343

44+
def test_empty_string():
45+
"""
46+
Test empty string is OK.
47+
48+
https://github.com/jquast/wcwidth/issues/24
49+
"""
50+
phrase = ""
51+
expect_length_each = 0
52+
expect_length_phrase = 0
53+
54+
# exercise,
55+
length_each = wcwidth.wcwidth(phrase)
56+
length_phrase = wcwidth.wcswidth(phrase)
57+
58+
# verify.
59+
assert length_each == expect_length_each
60+
assert length_phrase == expect_length_phrase
61+
62+
4463
def basic_string_type():
4564
"""
4665
This is a python 2-specific test of the basic "string type"

wcwidth/wcwidth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def wcwidth(wc, unicode_version='auto'):
134134
135135
See :ref:`Specification` for details of cell measurement.
136136
"""
137-
ucs = ord(wc)
137+
ucs = ord(wc) if wc else 0
138138

139139
# small optimization: early return of 1 for printable ASCII, this provides
140140
# approximately 40% performance improvement for mostly-ascii documents, with

0 commit comments

Comments
 (0)