Skip to content

Commit dbe6b64

Browse files
committed
wip
1 parent 4613a9d commit dbe6b64

8 files changed

Lines changed: 4106 additions & 6 deletions

‎doc-build/md043.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ to the previous matching marker":
9696

9797
The simple form shown above works for most scenarios; if multiple loops are
9898
needed, the value `"^^"`, `"^^^"`, etc. can be used in conjunction. To avoid
99-
infinite loops, matching fails if there are more than 10,000 loops.
99+
infinite loops, matching fails if there are more than 1,000 loops.
100100

101101
When an error is detected, this rule outputs the line number of the first
102102
problematic heading (otherwise, it outputs the last line number of the file).

‎doc/Rules.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1941,7 +1941,7 @@ to the previous matching marker":
19411941

19421942
The simple form shown above works for most scenarios; if multiple loops are
19431943
needed, the value `"^^"`, `"^^^"`, etc. can be used in conjunction. To avoid
1944-
infinite loops, matching fails if there are more than 10,000 loops.
1944+
infinite loops, matching fails if there are more than 1,000 loops.
19451945

19461946
When an error is detected, this rule outputs the line number of the first
19471947
problematic heading (otherwise, it outputs the last line number of the file).

‎doc/md043.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ to the previous matching marker":
107107

108108
The simple form shown above works for most scenarios; if multiple loops are
109109
needed, the value `"^^"`, `"^^^"`, etc. can be used in conjunction. To avoid
110-
infinite loops, matching fails if there are more than 10,000 loops.
110+
infinite loops, matching fails if there are more than 1,000 loops.
111111

112112
When an error is detected, this rule outputs the line number of the first
113113
problematic heading (otherwise, it outputs the last line number of the file).

‎lib/md043.mjs‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @ts-check
22

3-
import { addErrorContext, addErrorDetailIf } from "../helpers/helpers.cjs";
3+
import { addError, addErrorContext, addErrorDetailIf } from "../helpers/helpers.cjs";
44
import { getHeadingLevel, getHeadingText } from "../helpers/micromark-helpers.cjs";
55
import { filterByTypesCached } from "./cache.mjs";
66

@@ -40,6 +40,7 @@ export default {
4040
const requiredHeadings = headings.map((heading) => headingsItemsRe.test(heading) ? heading : "[Invalid syntax]");
4141
const matchCase = params.config.match_case || false;
4242
let i = 0;
43+
let loopsRemaining = 1000;
4344
let matchAny = false;
4445
let hasError = false;
4546
let anyHeadings = false;
@@ -62,6 +63,7 @@ export default {
6263
if (requiredHeadings[j] === expected) {
6364
i = j + 1;
6465
expected = getExpected();
66+
loopsRemaining--;
6567
break;
6668
}
6769
}
@@ -72,7 +74,10 @@ export default {
7274
}
7375
}
7476

75-
if (expected === "*") {
77+
if (loopsRemaining < 0) {
78+
addError(onError, heading.startLine, "Too many loops");
79+
hasError = true;
80+
} else if (expected === "*") {
7681
const nextExpected = getExpected();
7782
if (!headingIsExpected(actual, nextExpected, matchCase)) {
7883
matchAny = true;

0 commit comments

Comments
 (0)