From: Keith Packard Date: Sun, 5 Jan 2025 16:51:03 -0800 Subject: 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 --- test/normalize.py | 4 ++-- test/pathological_tests.py | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/test/normalize.py b/test/normalize.py index b7fd9b2..ec4979c 100644 --- a/test/normalize.py +++ b/test/normalize.py @@ -18,7 +18,7 @@ import re # Normalization code, adapted from # https://github.com/karlcow/markdown-testsuite/ significant_attrs = ["alt", "href", "src", "title"] -whitespace_re = re.compile('\s+') +whitespace_re = re.compile('\\s+') class MyHTMLParser(HTMLParser): def __init__(self): HTMLParser.__init__(self) @@ -176,7 +176,7 @@ def normalize_html(html): '\u2200&><"' """ - html_chunk_re = re.compile("(\|\<[^>]*\>|[^<]+)") + html_chunk_re = re.compile("(\\|\\<[^>]*\\>|[^<]+)") try: parser = MyHTMLParser() # We work around HTMLParser's limitations parsing CDATA diff --git a/test/pathological_tests.py b/test/pathological_tests.py index f556a1d..80b5261 100644 --- a/test/pathological_tests.py +++ b/test/pathological_tests.py @@ -30,7 +30,7 @@ def hash_collisions(): document = ''.join("[%s]: /url\n\n[%s]\n\n" % (key, bad_key) for key in collisions) - return document, re.compile("(

\[%s\]

\n){%d}" % (bad_key, COUNT-1)) + return document, re.compile("(

\\[%s\\]

\n){%d}" % (bad_key, COUNT-1)) allowed_failures = {"many references": True} @@ -48,10 +48,10 @@ pathological = { re.compile("(_a ){64999}_a")), "many link closers with no openers": (("a]" * 65000), - re.compile("(a\]){65000}")), + re.compile("(a\\]){65000}")), "many link openers with no closers": (("[a" * 65000), - re.compile("(\[a){65000}")), + re.compile("(\\[a){65000}")), "mismatched openers and closers": (("*a_ " * 50000), re.compile("([*]a[_] ){49999}[*]a_")), @@ -60,19 +60,19 @@ pathological = { re.compile("a[*][*]b(c[*] ){49999}c[*]")), "link openers and emph closers": (("[ a_" * 50000), - re.compile("(\[ a_){50000}")), + re.compile("(\\[ a_){50000}")), "pattern [ (]( repeated": (("[ (](" * 80000), - re.compile("(\[ \(\]\(){80000}")), + re.compile("(\\[ \\(\\]\\(){80000}")), "pattern ![[]() repeated": ("![[]()" * 160000, - re.compile("(!\[){160000}")), + re.compile("(!\\[){160000}")), "hard link/emph case": ("**x [a*b**c*](d)", re.compile("\\*\\*x ab\\*\\*c")), "nested brackets": (("[" * 50000) + "a" + ("]" * 50000), - re.compile("\[{50000}a\]{50000}")), + re.compile("\\[{50000}a\\]{50000}")), "nested block quotes": ((("> " * 50000) + "a"), re.compile("(
\n){50000}")), @@ -87,13 +87,13 @@ pathological = { re.compile("^

[e`]*

\n$")), "unclosed links A": ("[a](aaa

\n\n\n\n\n\n\n\n(\n\n\n\n\n\n\n\n\n){29999}\n
bbb
aaa
bbb
-\x0b
\n$")),