Skip to content

Commit 1b4b4f1

Browse files
committed
Fix len() for py
1 parent eca44f9 commit 1b4b4f1

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

py/vimlfunc.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,11 @@ def viml_keys(obj):
131131
return obj.keys()
132132

133133
def viml_len(obj):
134-
if type(obj) is str:
135-
return len(obj.encode('utf-8'))
134+
try:
135+
if type(obj) is str:
136+
return len(obj.encode('utf-8', 'ignore'))
137+
except UnicodeDecodeError:
138+
pass
136139
return len(obj)
137140

138141
def viml_printf(*args):

py/vimlparser.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,11 @@ def viml_keys(obj):
131131
return obj.keys()
132132

133133
def viml_len(obj):
134-
if type(obj) is str:
135-
return len(obj.encode('utf-8'))
134+
try:
135+
if type(obj) is str:
136+
return len(obj.encode('utf-8', 'ignore'))
137+
except UnicodeDecodeError:
138+
pass
136139
return len(obj)
137140

138141
def viml_printf(*args):

0 commit comments

Comments
 (0)