Bug #194095 - Validate dispatch-conf input in order to
authorZac Medico <zmedico@gentoo.org>
Fri, 5 Oct 2007 01:37:04 +0000 (01:37 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 5 Oct 2007 01:37:04 +0000 (01:37 -0000)
prevent spurious input characters from being interpreted
as user input (which can be quite confusing and gives
an "out of control" feeling). (trunk r7877)

svn path=/main/branches/2.1.2/; revision=7920

bin/dispatch-conf

index 5d33343f761212c9b4212e6c7d8f1be624b0094c..55bf13cfd5a3623700d7a1101046331864f7d63c 100755 (executable)
@@ -203,6 +203,8 @@ class dispatch:
         # Interactively process remaining
         #
 
+        valid_input = "qhtnmlezu"
+
         for conf in confs:
             count = count + 1
 
@@ -223,7 +225,16 @@ class dispatch:
                 print '>> (%i of %i) -- %s' % (count, len(confs), conf ['current'])
                 print '>> q quit, h help, n next, e edit-new, z zap-new, u use-new\n   m merge, t toggle-merge, l look-merge: ',
 
-                c = getch ()
+                # In some cases getch() will return some spurious characters
+                # that do not represent valid input. If we don't validate the
+                # input then the spurious characters can cause us to jump
+                # back into the above "diff" command immediatly after the user
+                # has exited it (which can be quite confusing and gives an
+                # "out of control" feeling).
+                while True:
+                    c = getch()
+                    if c in valid_input:
+                        break
 
                 if c == 'q':
                     sys.exit (0)
@@ -274,7 +285,7 @@ class dispatch:
                         os.unlink(mrgconf)
                     break
                 else:
-                    continue
+                    raise AssertionError("Invalid Input: %s" % c)
 
         if auto_zapped:
             print