Skip to content

Commit 2cd7a1a

Browse files
committed
test: Fix regex syntax errors
The regular expressions in normalize.py and pathological_tests.py are missing a lot of backslashes -- you need two in the source file to get one in the string. Signed-off-by: Keith Packard <keithp@keithp.com>
1 parent 80d687b commit 2cd7a1a

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

test/normalize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class HTMLParseError(Exception):
1818
# Normalization code, adapted from
1919
# https://github.com/karlcow/markdown-testsuite/
2020
significant_attrs = ["alt", "href", "src", "title"]
21-
whitespace_re = re.compile('\s+')
21+
whitespace_re = re.compile('\\s+')
2222
class MyHTMLParser(HTMLParser):
2323
def __init__(self):
2424
HTMLParser.__init__(self)
@@ -176,7 +176,7 @@ def normalize_html(html):
176176
'\u2200&amp;&gt;&lt;&quot;'
177177
178178
"""
179-
html_chunk_re = re.compile("(\<!\[CDATA\[.*?\]\]\>|\<[^>]*\>|[^<]+)")
179+
html_chunk_re = re.compile("(\\<!\\[CDATA\\[.*?\\]\\]\\>|\\<[^>]*\\>|[^<]+)")
180180
try:
181181
parser = MyHTMLParser()
182182
# We work around HTMLParser's limitations parsing CDATA

test/pathological_tests.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def badhash(ref):
3030

3131
document = ''.join("[%s]: /url\n\n[%s]\n\n" % (key, bad_key) for key in collisions)
3232

33-
return document, re.compile("(<p>\[%s\]</p>\n){%d}" % (bad_key, COUNT-1))
33+
return document, re.compile("(<p>\\[%s\\]</p>\n){%d}" % (bad_key, COUNT-1))
3434

3535
allowed_failures = {"many references": True}
3636

@@ -48,10 +48,10 @@ def badhash(ref):
4848
re.compile("(_a ){64999}_a")),
4949
"many link closers with no openers":
5050
(("a]" * 65000),
51-
re.compile("(a\]){65000}")),
51+
re.compile("(a\\]){65000}")),
5252
"many link openers with no closers":
5353
(("[a" * 65000),
54-
re.compile("(\[a){65000}")),
54+
re.compile("(\\[a){65000}")),
5555
"mismatched openers and closers":
5656
(("*a_ " * 50000),
5757
re.compile("([*]a[_] ){49999}[*]a_")),
@@ -60,19 +60,19 @@ def badhash(ref):
6060
re.compile("a[*][*]b(c[*] ){49999}c[*]")),
6161
"link openers and emph closers":
6262
(("[ a_" * 50000),
63-
re.compile("(\[ a_){50000}")),
63+
re.compile("(\\[ a_){50000}")),
6464
"pattern [ (]( repeated":
6565
(("[ (](" * 80000),
66-
re.compile("(\[ \(\]\(){80000}")),
66+
re.compile("(\\[ \\(\\]\\(){80000}")),
6767
"pattern ![[]() repeated":
6868
("![[]()" * 160000,
69-
re.compile("(!\[<a href=\"\"></a>){160000}")),
69+
re.compile("(!\\[<a href=\"\"></a>){160000}")),
7070
"hard link/emph case":
7171
("**x [a*b**c*](d)",
7272
re.compile("\\*\\*x <a href=\"d\">a<em>b\\*\\*c</em></a>")),
7373
"nested brackets":
7474
(("[" * 50000) + "a" + ("]" * 50000),
75-
re.compile("\[{50000}a\]{50000}")),
75+
re.compile("\\[{50000}a\\]{50000}")),
7676
"nested block quotes":
7777
((("> " * 50000) + "a"),
7878
re.compile("(<blockquote>\n){50000}")),
@@ -87,13 +87,13 @@ def badhash(ref):
8787
re.compile("^<p>[e`]*</p>\n$")),
8888
"unclosed links A":
8989
("[a](<b" * 30000,
90-
re.compile("(\[a\]\(&lt;b){30000}")),
90+
re.compile("(\\[a\\]\\(&lt;b){30000}")),
9191
"unclosed links B":
9292
("[a](b" * 30000,
93-
re.compile("(\[a\]\(b){30000}")),
93+
re.compile("(\\[a\\]\\(b){30000}")),
9494
"unclosed <!--":
9595
("</" + "<!--" * 300000,
96-
re.compile("\&lt;\/(\&lt;!--){300000}")),
96+
re.compile("\\&lt;\\/(\\&lt;!--){300000}")),
9797
"tables":
9898
("aaa\rbbb\n-\v\n" * 30000,
9999
re.compile("^<p>aaa</p>\n<table>\n<thead>\n<tr>\n<th>bbb</th>\n</tr>\n</thead>\n<tbody>\n(<tr>\n<td>aaa</td>\n</tr>\n<tr>\n<td>bbb</td>\n</tr>\n<tr>\n<td>-\x0b</td>\n</tr>\n){29999}</tbody>\n</table>\n$")),

0 commit comments

Comments
 (0)