Fix editor spawning on null-string EDITOR and VISUAL.
authorW. Trevor King <wking@drexel.edu>
Fri, 29 Jan 2010 12:32:41 +0000 (07:32 -0500)
committerW. Trevor King <wking@drexel.edu>
Fri, 29 Jan 2010 12:32:41 +0000 (07:32 -0500)
  $ EDITOR= VISUAL= python -c 'import os; import sys; print os.environ'
  {..., 'EDITOR': '', ..., 'VISUAL': '', ...}

libbe/ui/util/editor.py

index ce1436528d20872a07967e9ce28c892e159efece..1a430c703728934db321abc2e614e50080ccb9d3 100644 (file)
@@ -64,13 +64,12 @@ def editor_string(comment=None, encoding=None):
     """
     if encoding == None:
         encoding = libbe.util.encoding.get_filesystem_encoding()
+    editor = None
     for name in ('VISUAL', 'EDITOR'):
-        try:
+        if name in os.environ and os.environ[name] != '':
             editor = os.environ[name]
             break
-        except KeyError:
-            pass
-    else:
+    if editor == None:
         raise CantFindEditor()
     fhandle, fname = tempfile.mkstemp()
     try: