[XML-SIG] Problem with adr_parse.py

adrien.rebollo@gmx.fr adrien.rebollo@gmx.fr
Tue, 2 Jul 2002 23:44:38 +0200


--a8Wt8u1KmwUX3Y2C
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hello,

The parser for Opera .adr files has a bug, at least with Opera 6 :
if an optional field is not there, for example "VISITED", the parser
goes one line too far, and all gets messed up.

See attached patch.

Adrien Rebollo
-- 

--a8Wt8u1KmwUX3Y2C
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="adr.patch"

--- adr_parse.py	Wed May  1 11:57:31 2002
+++ /home/rebollo/PyXML-0.7.1/demo/xbel/adr_parse.py	Tue Jul  2 23:28:44 2002
@@ -21,12 +21,16 @@
 # --- Methods
 
 def readfield(infile, fieldname, required = 1):
-    line = string.rstrip(infile.readline())
+    line = infile.readline()
+    linelength = len(line)
     pos = string.find(line,fieldname+"=")
     if pos == -1 and required:
         raise OperaParseException("Field '%s' missing" % fieldname)
 
-    return line[pos+len(fieldname)+1:]
+    if pos == -1 and required == 0:
+        infile.seek(-linelength, 1)
+
+    return string.rstrip(line[pos+len(fieldname)+1:])
 
 def swallow_rest(infile):
     "Reads input until first blank line."

--a8Wt8u1KmwUX3Y2C--