Skip to content

Commit

Permalink
bugfix empty string to wcwidth() while we're here
Browse files Browse the repository at this point in the history
  • Loading branch information
jquast committed Oct 19, 2023
1 parent c3cd589 commit 0a5aa0d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 0 additions & 1 deletion bin/update-tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import logging
import datetime
import functools
import collections
import unicodedata
from pathlib import Path
from dataclasses import field, fields, dataclass
Expand Down
19 changes: 19 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ def test_package_version():
assert result == expected


def test_empty_string():
"""
Test empty string is OK.
https://github.com/jquast/wcwidth/issues/24
"""
phrase = ""
expect_length_each = 0
expect_length_phrase = 0

# exercise,
length_each = wcwidth.wcwidth(phrase)
length_phrase = wcwidth.wcswidth(phrase)

# verify.
assert length_each == expect_length_each
assert length_phrase == expect_length_phrase


def basic_string_type():
"""
This is a python 2-specific test of the basic "string type"
Expand Down
2 changes: 1 addition & 1 deletion wcwidth/wcwidth.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def wcwidth(wc, unicode_version='auto'):
See :ref:`Specification` for details of cell measurement.
"""
ucs = ord(wc)
ucs = ord(wc) if wc else 0

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

0 comments on commit 0a5aa0d

Please sign in to comment.