From 0a49e1b07324c749be1757fc58c22ef73a3e43d3 Mon Sep 17 00:00:00 2001 From: Samuel Clay Date: Thu, 9 Aug 2018 10:01:59 -0400 Subject: [PATCH] Attempting to corral APNS push notification max sizes due to chinese unicode characters being 3 bytes. --- utils/story_functions.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/utils/story_functions.py b/utils/story_functions.py index 1a5bdc146..22fed4848 100644 --- a/utils/story_functions.py +++ b/utils/story_functions.py @@ -272,11 +272,13 @@ def linkify(*args, **kwargs): return xhtml_unescape_tornado(linkify_tornado(*args, **kwargs)) def truncate_chars(value, max_length): - if len(value) <= max_length: + if isinstance(value, unicode): + uvalue = value.encode('utf-8') + if len(uvalue) <= max_length: return value - truncd_val = value[:max_length] - if value[max_length] != " ": + truncd_val = uvalue[:max_length] + if uvalue[max_length] != " ": rightmost_space = truncd_val.rfind(" ") if rightmost_space != -1: truncd_val = truncd_val[:rightmost_space]