Failure of ANSI library when reciving "Erase in Line" ANSI escape code

Bug #1477472 reported by Martyn Welch
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
pexpect (Ubuntu)
New
Undecided
Unassigned

Bug Description

There is a bug in the 12.04 pexpect package that results in the ANSI library throwing an exception when it receives the "Erase in Line" escape code ("ESC[2K"):

Traceback (most recent call last):
  File "./pexpect-check.py", line 12, in <module>
    screen.write("%c[2K" %(0x1B))
  File "/usr/lib/python2.7/dist-packages/ANSI.py", line 257, in write
    self.process(c)
  File "/usr/lib/python2.7/dist-packages/ANSI.py", line 248, in process
    self.state.process(c)
  File "/usr/lib/python2.7/dist-packages/FSM.py", line 223, in process
    self.action (self)
  File "/usr/lib/python2.7/dist-packages/ANSI.py", line 118, in DoEraseLine
    if arg == 0:
NameError: global name 'arg' is not defined

The following test code can be used to test for this failure:

#!/usr/bin/env python
import sys
import ANSI

print "Testing operation of \"DoEraseLine\" in ANSI library: ",

screen = ANSI.ANSI(25,80)

screen.write("This line should be deleted")
#print screen.pretty()

try:
 screen.write("%c[2K" %(0x1B))
 #print screen.pretty()

except:
 print "FAIL"
 sys.exit(1)

print "PASS"
sys.exit(0)

This has been fixed in later versions of pexpect, but is broken in the (still supported?) version in precise. The minimal patch required to resolve this issue is:

--- ANSI.py.orig 2015-07-23 10:22:11.561742106 +0100
+++ ANSI.py 2015-07-23 10:22:29.841339490 +0100
@@ -114,6 +114,7 @@

 def DoEraseLine (fsm):

+ arg = int(fsm.memory.pop())
     screen = fsm.memory[0]
     if arg == 0:
         screen.end_of_line()

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.