fix: fix infinite loop for indented code blank line (#3947)

* fix: fix infinite loop for indented code blank line

* set redos tests to not silent

* simplify test

* fix test
This commit is contained in:
Tony Brix
2026-04-18 07:06:46 -06:00
committed by GitHub
parent 98b38246c0
commit 58a52e8a49
4 changed files with 35 additions and 15 deletions
+29 -14
View File
@@ -110,7 +110,15 @@ export class _Lexer<ParserOutput = string, RendererOutput = string> {
src = src.replace(other.tabCharGlobal, ' ').replace(other.spaceLine, '');
}
let srcLength = Infinity;
while (src) {
if (src.length < srcLength) {
srcLength = src.length;
} else {
this.infiniteLoopError(src.charCodeAt(0));
break;
}
let token: Tokens.Generic | undefined;
if (this.options.extensions?.block?.some((extTokenizer) => {
@@ -275,13 +283,8 @@ export class _Lexer<ParserOutput = string, RendererOutput = string> {
}
if (src) {
const errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
if (this.options.silent) {
console.error(errMsg);
break;
} else {
throw new Error(errMsg);
}
this.infiniteLoopError(src.charCodeAt(0));
break;
}
}
@@ -334,7 +337,15 @@ export class _Lexer<ParserOutput = string, RendererOutput = string> {
let keepPrevChar = false;
let prevChar = '';
let srcLength = Infinity;
while (src) {
if (src.length < srcLength) {
srcLength = src.length;
} else {
this.infiniteLoopError(src.charCodeAt(0));
break;
}
if (!keepPrevChar) {
prevChar = '';
}
@@ -464,16 +475,20 @@ export class _Lexer<ParserOutput = string, RendererOutput = string> {
}
if (src) {
const errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
if (this.options.silent) {
console.error(errMsg);
break;
} else {
throw new Error(errMsg);
}
this.infiniteLoopError(src.charCodeAt(0));
break;
}
}
return tokens;
}
private infiniteLoopError(byte: number) {
const errMsg = 'Infinite loop on byte: ' + byte;
if (this.options.silent) {
console.error(errMsg);
} else {
throw new Error(errMsg);
}
}
}
+1 -1
View File
@@ -112,7 +112,7 @@ export function rtrim(str: string, c: string, invert?: boolean) {
export function trimTrailingBlankLines(str: string) {
const lines = str.split('\n');
let end = lines.length - 1;
while (end >= 0 && !lines[end].trim()) {
while (end >= 0 && other.blankLine.test(lines[end])) {
end--;
}
if (lines.length - end <= 2) {
+1
View File
@@ -47,4 +47,5 @@ runTests({
runTests({
tests: redosTests,
parse,
defaultMarkedOptions: { silent: false },
});
+4
View File
@@ -0,0 +1,4 @@
module.exports = {
markdown: '\t\v\n',
html: '<pre><code>\v</code></pre>\n',
};