cmark

My personal build of CMark ✏️

Commit
c9875cbbbe293e6727a7a25b79e7ea4949ef5670
Parent
698dab76847e5d671cce42a0c0ce2c98c5f07776
Author
John MacFarlane <jgm@berkeley.edu>
Date

runtests.py: catch HTMLParser errors in normalizer.

Diffstat

1 file changed, 9 insertions, 5 deletions

Status File Name N° Changes Insertions Deletions
Modified runtests.py 14 9 5
diff --git a/runtests.py b/runtests.py
@@ -7,7 +7,7 @@ import platform
 from difflib import unified_diff
 from subprocess import *
 import argparse
-from HTMLParser import HTMLParser
+from HTMLParser import HTMLParser, HTMLParseError
 from htmlentitydefs import name2codepoint
 import re
 import cgi
@@ -180,10 +180,14 @@ def normalize_html(html):
     * HTMLParser just swallows CDATA.
     * HTMLParser seems to treat unknown declarations as comments.
     """
-    parser = MyHTMLParser()
-    parser.feed(html.decode(encoding='UTF-8'))
-    parser.close()
-    return parser.output
+    try:
+        parser = MyHTMLParser()
+        parser.feed(html.decode(encoding='UTF-8'))
+        parser.close()
+        return parser.output
+    except HTMLParseError as e:
+        sys.stderr.write("Normalization error: " + e.msg + "\n")
+        return html  # on error, return unnormalized HTML
 
 def print_test_header(headertext, example_number, start_line, end_line):
     print "Example %d (lines %d-%d) %s" % (example_number,start_line,end_line,headertext)