jseutter / ofxparse

Ofx file format parser for Python
http://sites.google.com/site/ofxparse/
MIT License
204 stars 121 forks source link

OfxPreprocessedFile() crashes on an empty close tag like this: <MEMO/> #167

Open toddInPortland opened 2 years ago

toddInPortland commented 2 years ago

tokens that look like cause OfxPreprocessedFile() to set is_closing_tag=false and is_open_tag=true which, in turn causes re.findall() to fault. This flavor of token appears in the ofx file from my credit union, onpointcu.com. It may be encoded wrong, but the right fix would be a better parse code that does not allow the code to fault.

The fix is to add change OfxPreprocessedFile() so that is_closing_tag accounts for this. I can push the patch, but I would need permission to push.

--- a/ofxparse/ofxparse.py
+++ b/ofxparse/ofxparse.py
@@ -169,7 +169,7 @@ class OfxPreprocessedFile(OfxFile):
         tokens = re.split(r'(?i)(</?[a-z0-9_\.]+>)', ofx_string)
         new_fh = StringIO()
         for token in tokens:
-            is_closing_tag = token.startswith('</')
+            is_closing_tag = token.startswith('</') or token.endswith('/>')
             is_processing_tag = token.startswith('<?')
             is_cdata = token.startswith('<!')
             is_tag = token.startswith('<') and not is_cdata