[tor-commits] [arm/master] fix: cropping whitespace-only strings could crash

atagar at torproject.org atagar at torproject.org
Sat Jun 18 23:14:48 UTC 2011


commit 4aa35c2f4ad2445a948a05f46b07a7636ff2aac3
Author: Damian Johnson <atagar at torproject.org>
Date:   Fri Jun 17 20:06:55 2011 -0700

    fix: cropping whitespace-only strings could crash
    
    When cropping strings that started with whitespace and we didn't have enough
    room for any of the words we would crash (index error due to referencing the
    -1 index of an empty string).
---
 src/util/uiTools.py |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/src/util/uiTools.py b/src/util/uiTools.py
index ce467c3..40a3087 100644
--- a/src/util/uiTools.py
+++ b/src/util/uiTools.py
@@ -273,7 +273,8 @@ def cropStr(msg, size, minWordLen = 4, minCrop = 0, endType = Ending.ELLIPSE, ge
   else: returnMsg, remainder = msg[:lastWordbreak], msg[lastWordbreak:]
   
   # if this is ending with a comma or period then strip it off
-  if not getRemainder and returnMsg[-1] in (",", "."): returnMsg = returnMsg[:-1]
+  if not getRemainder and returnMsg and returnMsg[-1] in (",", "."):
+    returnMsg = returnMsg[:-1]
   
   if endType == Ending.ELLIPSE:
     returnMsg = returnMsg.rstrip() + "..."





More information about the tor-commits mailing list