|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+<?php
|
|
|
2
|
+declare(strict_types=1);
|
|
|
3
|
+
|
|
|
4
|
+use PHPUnit\Framework\TestCase;
|
|
|
5
|
+
|
|
|
6
|
+require_once __DIR__ . '/../php/markdown.php';
|
|
|
7
|
+
|
|
|
8
|
+final class BrokenSyntaxTests extends TestCase {
|
|
|
9
|
+ private ?Markdown $parser = null;
|
|
|
10
|
+
|
|
|
11
|
+ protected function setUp(): void {
|
|
|
12
|
+ parent::setUp();
|
|
|
13
|
+ $this->parser = Markdown::completeParser();
|
|
|
14
|
+ }
|
|
|
15
|
+
|
|
|
16
|
+ private function iterateCharacters(string $markdown) {
|
|
|
17
|
+ for ($i = 1; $i < mb_strlen($markdown); $i++) {
|
|
|
18
|
+ $portion = mb_substr($markdown, 0, $i);
|
|
|
19
|
+ try {
|
|
|
20
|
+ $this->parser->toHTML($portion);
|
|
|
21
|
+ } catch (Error $e) {
|
|
|
22
|
+ print("Broken portion is:\n\"{$portion}\"\n");
|
|
|
23
|
+ throw $e;
|
|
|
24
|
+ }
|
|
|
25
|
+ }
|
|
|
26
|
+ }
|
|
|
27
|
+
|
|
|
28
|
+ public function test_brokenSyntax() {
|
|
|
29
|
+ // Just try a bunch of broken syntax and make sure no exceptions are
|
|
|
30
|
+ // thrown or infinite loops triggered. Don't care about what's rendered
|
|
|
31
|
+ // as most of these are incomplete or invalid syntax.
|
|
|
32
|
+ $this->iterateCharacters("# ");
|
|
|
33
|
+ $this->iterateCharacters("## ");
|
|
|
34
|
+ $this->iterateCharacters("Underlined\n-");
|
|
|
35
|
+ $this->iterateCharacters("* ");
|
|
|
36
|
+ $this->iterateCharacters(" * A");
|
|
|
37
|
+ $this->iterateCharacters("- A");
|
|
|
38
|
+ $this->iterateCharacters(" - A");
|
|
|
39
|
+ $this->iterateCharacters("+ A");
|
|
|
40
|
+ $this->iterateCharacters(" + A");
|
|
|
41
|
+ $this->iterateCharacters("1. A");
|
|
|
42
|
+ $this->iterateCharacters(" 1. A");
|
|
|
43
|
+ $this->iterateCharacters("1. A\n 1. B\n 2. C\n2. D");
|
|
|
44
|
+ $this->iterateCharacters("> A");
|
|
|
45
|
+ $this->iterateCharacters("> \nA");
|
|
|
46
|
+ $this->iterateCharacters("> \n>");
|
|
|
47
|
+ $this->iterateCharacters(">>");
|
|
|
48
|
+ $this->iterateCharacters("> > A");
|
|
|
49
|
+ $this->iterateCharacters("> \n> A");
|
|
|
50
|
+ $this->iterateCharacters("> > \n> A");
|
|
|
51
|
+ $this->iterateCharacters("```\ncode\n```");
|
|
|
52
|
+ $this->iterateCharacters("```java\ncode\n```");
|
|
|
53
|
+ $this->iterateCharacters(" code\n code\n\n");
|
|
|
54
|
+ $this->iterateCharacters("------");
|
|
|
55
|
+ $this->iterateCharacters(" - - - --*");
|
|
|
56
|
+ $this->iterateCharacters("Header|Header\n--|--\nCell|Cell");
|
|
|
57
|
+ $this->iterateCharacters("Header\n--|--\nCell");
|
|
|
58
|
+ $this->iterateCharacters("|Header|\n|-|\n|Cell|");
|
|
|
59
|
+ $this->iterateCharacters("|Header|\n|--|--|--|\n|Cell|");
|
|
|
60
|
+ $this->iterateCharacters("|Header|Header|\n|--|\n|Cell|Cell|");
|
|
|
61
|
+ $this->iterateCharacters("|Header|\n|:-|\n|Cell|");
|
|
|
62
|
+ $this->iterateCharacters("|Header|\n|:-:|\n|Cell|");
|
|
|
63
|
+ $this->iterateCharacters("|Header|\n|-:|\n|Cell|");
|
|
|
64
|
+ $this->iterateCharacters("term\n: definition\nterm\n: definition");
|
|
|
65
|
+ $this->iterateCharacters("term\n:definition\nterm\n:definition");
|
|
|
66
|
+ $this->iterateCharacters("HTML\n\n*[HTML]: Hypertext");
|
|
|
67
|
+ $this->iterateCharacters("HTML\n*[HTML]: Hypertext");
|
|
|
68
|
+ $this->iterateCharacters("*[HTML]: Hypertext\nHTML");
|
|
|
69
|
+ $this->iterateCharacters("---{.foo}\n");
|
|
|
70
|
+ $this->iterateCharacters("---{#foo}\n");
|
|
|
71
|
+ $this->iterateCharacters("---{.foo #foo lang=en}\n");
|
|
|
72
|
+ $this->iterateCharacters("lorem *ipsum* dolor *sit* amet");
|
|
|
73
|
+ $this->iterateCharacters("*lorem* ipsum *dolor* sit *amet*");
|
|
|
74
|
+ $this->iterateCharacters("*lorem *ipsum *dolor*** sit");
|
|
|
75
|
+ $this->iterateCharacters("***lorem* ipsum* dolor* sit");
|
|
|
76
|
+ $this->iterateCharacters("lorem _ipsum_ dolor _sit_ amet");
|
|
|
77
|
+ $this->iterateCharacters("_lorem_ ipsum _dolor_ sit _amet_");
|
|
|
78
|
+ $this->iterateCharacters("_lorem _ipsum _dolor___ sit");
|
|
|
79
|
+ $this->iterateCharacters("___lorem_ ipsum_ dolor_ sit");
|
|
|
80
|
+ $this->iterateCharacters("lorem **ipsum** dolor **sit** amet");
|
|
|
81
|
+ $this->iterateCharacters("**lorem** ipsum **dolor** sit **amet**");
|
|
|
82
|
+ $this->iterateCharacters("**lorem **ipsum **dolor****** sit");
|
|
|
83
|
+ $this->iterateCharacters("******lorem** ipsum** dolor** sit");
|
|
|
84
|
+ $this->iterateCharacters("lorem __ipsum__ dolor __sit__ amet");
|
|
|
85
|
+ $this->iterateCharacters("__lorem__ ipsum __dolor__ sit __amet__");
|
|
|
86
|
+ $this->iterateCharacters("lorem __ipsum__ dolor __sit__ amet");
|
|
|
87
|
+ $this->iterateCharacters("__lorem __ipsum __dolor______ sit");
|
|
|
88
|
+ $this->iterateCharacters("______lorem__ ipsum__ dolor__ sit");
|
|
|
89
|
+ $this->iterateCharacters("*_**`~~^==!__~*^!``**-+!**`==!~_^**``_");
|
|
|
90
|
+ $this->iterateCharacters("[link[(index.html(");
|
|
|
91
|
+ $this->iterateCharacters("[link[](index.html()");
|
|
|
92
|
+ $this->iterateCharacters("[link]](index.html))");
|
|
|
93
|
+ $this->iterateCharacters("[[link]((index.html)");
|
|
|
94
|
+ $this->iterateCharacters("]link])index.html)");
|
|
|
95
|
+ $this->iterateCharacters("[ link ] ( index.html )");
|
|
|
96
|
+ $this->iterateCharacters("(user@example.com)");
|
|
|
97
|
+ $this->iterateCharacters("(https://user@example.com)");
|
|
|
98
|
+ $this->iterateCharacters("(index.html \"title\")");
|
|
|
99
|
+ $this->iterateCharacters("(index.html \"title)");
|
|
|
100
|
+ $this->iterateCharacters("(index.html title\")");
|
|
|
101
|
+ $this->iterateCharacters("(index.html title)");
|
|
|
102
|
+ $this->iterateCharacters("![alt][image.jpg]");
|
|
|
103
|
+ $this->iterateCharacters("");
|
|
|
104
|
+ $this->iterateCharacters("! [alt](image.jpg)");
|
|
|
105
|
+ $this->iterateCharacters("!(image.jpg)");
|
|
|
106
|
+ $this->iterateCharacters("[][]]][][[][][][[][[]][][][][][[[]]]][]][][");
|
|
|
107
|
+ $this->iterateCharacters("())())()()()(())(()((())))(()((()");
|
|
|
108
|
+ $this->iterateCharacters("<https://example.com>");
|
|
|
109
|
+ $this->iterateCharacters("<<https://example.com>");
|
|
|
110
|
+ $this->iterateCharacters("<https://example.com>>");
|
|
|
111
|
+ $this->iterateCharacters("[link][ref]\n\n[ref]: page.html");
|
|
|
112
|
+ $this->iterateCharacters("[link][ref]\n[ref]: page.html");
|
|
|
113
|
+ $this->iterateCharacters("[link][ref]\n\n[ref]:page.html");
|
|
|
114
|
+ $this->iterateCharacters("[ref]: page.html\n\n[link][ref]");
|
|
|
115
|
+ $this->iterateCharacters("[link][ref]\n\n[ref]: page.html \"title\"");
|
|
|
116
|
+ $this->iterateCharacters("[link][ref]\n\n[ref]: page.html title");
|
|
|
117
|
+ $this->iterateCharacters("Lorem[^1] ipsum[^abc] dolor[^-1]\n\n[^abc]: def\n[^1]: def\n[^-1]: def\n[^abc]: def");
|
|
|
118
|
+ $this->iterateCharacters("Lorem[^1]\n\n[^2]: def");
|
|
|
119
|
+ $this->iterateCharacters("[^1]] [[^2] [^3]] [[^4]] ]^5[");
|
|
|
120
|
+ $this->iterateCharacters("[^1]: Def\n\nLorem[^1]");
|
|
|
121
|
+ $this->iterateCharacters("[^1]: Def\n\nLorem[^2]");
|
|
|
122
|
+ $this->iterateCharacters("Lorem <foo> ipsum");
|
|
|
123
|
+ $this->iterateCharacters("Lorem <span> ipsum");
|
|
|
124
|
+ $this->iterateCharacters("Lorem <span class=\"foo\" id=\"foo\" lang=\"en\"> ipsum");
|
|
|
125
|
+ $this->iterateCharacters("Lorem </span> ipsum");
|
|
|
126
|
+ $this->iterateCharacters("Lorem </span foo=\"bar\">");
|
|
|
127
|
+ $this->iterateCharacters("Lorem <span foo='bar' baz=ipsum dolor> sit");
|
|
|
128
|
+ $this->iterateCharacters("\\*\\\\*\\\\\\*\\\\\\\\*\\*");
|
|
|
129
|
+ $this->assertTrue(true); // to suppress risky test warning
|
|
|
130
|
+ }
|
|
|
131
|
+}
|
|
|
132
|
+?>
|